Skip to content

Instantly share code, notes, and snippets.

@hivepress
Created April 26, 2022 17:29
Show Gist options
  • Select an option

  • Save hivepress/445d4fccae06a512f5410f28689e1b67 to your computer and use it in GitHub Desktop.

Select an option

Save hivepress/445d4fccae06a512f5410f28689e1b67 to your computer and use it in GitHub Desktop.
Make the price field optional for marketplace listings #hivepress #marketplace
<?php
add_filter(
'hivepress/v1/models/listing/attributes',
function( $attributes ) {
if ( isset( $attributes['price'] ) ) {
$attributes['price']['edit_field']['required'] = false;
}
return $attributes;
},
1000
);
@unitehearts

Copy link
Copy Markdown

Thanks for this.
Suppose we want it to be Required only for a few categories and Optional for a few other Categories, how can we do this ?
Someone in the community please help. Thanks.

@hivepress

hivepress commented May 27, 2025

Copy link
Copy Markdown
Author

This would require further customizations, probably for the hivepress/v1/models/listing/fields hook instead, because the attributes hook has no parameters for changing the field behavior depending on categories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment