Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active November 29, 2018 17:19
Show Gist options
  • Save jrick1229/98fee7a4ff3ceef2b20c708b408f2e0e to your computer and use it in GitHub Desktop.
Save jrick1229/98fee7a4ff3ceef2b20c708b408f2e0e to your computer and use it in GitHub Desktop.
Hide products by category from the shop page
<?php
/**
* Exclude products from a particular category on the shop page
*/
function wcs_hide_unwanted_category( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'not-displayed' ), // 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', 'wcs_hide_unwanted_category' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment