Skip to content

Instantly share code, notes, and snippets.

@sirwan
Created August 23, 2018 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirwan/eead31f1ea3f9cc30ea8ccab2657ac3c to your computer and use it in GitHub Desktop.
Save sirwan/eead31f1ea3f9cc30ea8ccab2657ac3c to your computer and use it in GitHub Desktop.
Exclude products from a particular category on the shop page
/**
* Exclude products from a particular category on the shop page
*/
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'clothing' ), // Don't display products in the clothing category on the shop page.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment