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
In the Listings Settings, there is currently an option to “Require file attachments”. I would like my Marketplace to have listing options for both digital goods and physical goods. I hope to achieve this by requiring File Attachment for a specific category, and allowing file attachment to be an option for other categories.
I am using the Code Snippet plugin to add PHP customizations, but it doesn’t seem to work completely. I would like help knowing why this doesn’t work.
<?php
add_filter(
'hivepress/v1/models/listing/attributes',
function( $attributes ) {
if ( isset( $attributes['attachments'] ) ) {
$attributes['attachments']['edit_field']['required'] = false;
// removes requirement for uploading a file in the listing. uploading file is now optional.
}
if ($attributes['categories'] == ['digital-downloads']) {
$attributes['attachments']['edit_field']['required'] = true;
// requires uploading a file in the listing if the category is digital-downloads
}
return $attributes;
},
1000
);
Basically, what I am trying to do here is to first make the file upload optional, and then make the file upload required if the selected category is Digital Downloads. The current result is that ALL categories allow OPTIONAL file upload. The Digital Downloads category is not requiring the file upload, the second argument doesn’t seem to be executed. I part of the code from here: Make attachments optional for marketplace listings #hivepress #marketplace · GitHub
EDIT: I can see your reply, andrii, but there is no way for me to respond. As I put in my post already, I tried this solution and it does nothing at all - there is no change to the behavior of the listing form. I would very much appreciate knowing why nothing I am trying works, as I just paid for this software!