Making digital file attachments optional for specific listing categories

In order to make selling digital products possible with the marketplace extension - you must “require file attachments” in Hivepress/Settings/Listings.

This makes it so that every single listing REQUIRES a digital product.

And although you can assign bookings to specific categories, you can’t assign only some categories to include digital products and allow other categories/listings to not require digital products.

If it were possible to assign/require digital file attachments to only some listings categories rather than requiring every listing to attach a file, you could make it so that some listings could be used to book appointments and other listings could be used to sell digital products.

:pray:

Hi,

Please try this PHP snippet (instead of numbers 1,2,3 - specify the categories where you want to show this attribute):

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

Please note that it can require further customization.
If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY

P.S. If you purchased a theme or extension, please enter the license key in the forum profile settings, this will enable the Premium Support badge and ensure a 24-hour turnaround time.

1 Like

Thanks for the response.

I downloaded the code snippets plugin and added the PHP snippet as you said to do above – replaying 1,2,3 with the categories I only want to require file attachments.

Ended up crashing the site :upside_down_face:

Restored from a backup and want to avoid crashing again – if the categories are all under one parent category, should I list only that one parent category instead?

Thanks!

just watched this and see how you say you recommend avoiding customizing the templates with php snippets, but also see that the child theme is no longer.

where/how do you recommend I place the PHP snippet? Still with the code snippets plugin?

Thanks

Hi,

We tested the code on our side, and it works without issues. Please check in more detail if you have entered the correct categories instead of numbers.
Also, please use the Code Snippets plugin to add and manage custom PHP code snippets.

If this issue persists, please send more details that may help to detect or reproduce this issue (e.g., a link to your site, screenshots, a list of installed plugins, or the error message you get).

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