27
0

Hide Particular Category In WooCommerce Shop Page

27
0

Put this code in function.php

Appearance -> Theme Editor -> Theme Function

/*** 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' ), // put the slugs here that you dont want to show.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}

add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

Leave a Reply

Your email address will not be published.