Selling: Require file attachments Only For Certain Category

Hello, in hivepress settings for the selling, I checked the

“Require file attachments” because I need vendors to be able to sell ebooks on my category Ebooks.

But for other categories makes no sense in my marketplace to have a file attachment as required.

Could this item be optional or can I only restrict it to the category ebooks?

Thanks

If it can help someone, to make file attachment optional, this is the snippet

<?php
add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset( $attributes['attachments'] ) ) {
			$attributes['attachments']['edit_field']['required'] = false;
		}
 
		return $attributes;
	},
	1000
);

Is it possible to chose wich categories have the file attachment?

2 Likes

Thanks for posting the solution! We also have this snippet in the Gist collection Make attachments optional for marketplace listings #hivepress #marketplace · GitHub

1 Like

Hi Ihor,

Is it possible to chose wich categories have the file attachment?

thanks

Please try this PHP snippet but please note that it needs additional testing. Please change 1,2,3 on the categories id where you want to show this field

add_filter( 
	'hivepress/v1/models/listing/attributes', 
	function ($attributes){
		if(isset($attributes['attachments'])){
			$attributes['attachments'] = array_merge($attributes['attachments'], ['categories' => [1,2,3]]);	
		}
		
		return $attributes;
	},
	1000
);
4 Likes

Thanks, it worked!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.