Skip to content

Instantly share code, notes, and snippets.

@squill
Last active January 11, 2019 13:20
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 squill/2ae0ab6820892e77bdccb18753592559 to your computer and use it in GitHub Desktop.
Save squill/2ae0ab6820892e77bdccb18753592559 to your computer and use it in GitHub Desktop.
Hide Product Categories
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'PUT THE CATEGORY TO HIDE HERE' ), // Don't display products in the this 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