Skip to content

Instantly share code, notes, and snippets.

@squill squill/hide-categories.php
Last active Jan 11, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.