Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save plugin-republic/d7f02d39772d1e7a43e4af2cf8a86cb0 to your computer and use it in GitHub Desktop.

Select an option

Save plugin-republic/d7f02d39772d1e7a43e4af2cf8a86cb0 to your computer and use it in GitHub Desktop.
<?php
/**
* Exclude specific products from a Product Categories field type
* Edit the $excluded_ids array below with the product IDs you want
* to hide. If you need different exclusions per field, check $args['category'] to
* identify the field and apply exclusions conditionally.
*/
add_filter( 'pewc_get_products_for_cats_args', function( $args ) {
// IDs of products to exclude from all Product Categories fields.
$excluded_ids = array( 123, 456 );
if ( ! empty( $args['exclude'] ) ) {
$args['exclude'] = array_merge( $args['exclude'], $excluded_ids );
} else {
$args['exclude'] = $excluded_ids;
}
return $args;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment