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
I also tried following these instructions, which did nothing: Selling: Require file attachments Only For Certain Category
These instructions also did nothing: Making digital file attachments optional for specific listing categories
Please advise, I appreciate your assistance!