Hi,
I’m having some issues with my shop page display. I would like to exclude one of the categories on my shop page. Specifically in the list of categories at the top of the page. I have tried adding the following to my child theme functions.php with no success.
/**
-
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’ );
However I have a php file in a woocommerce folder on the same level as the function.php file which contains a file called “content-product_cat.php” which I believe is controlling the shop page view. However I am not sure if the above code would work here.
I know often wooCommerce issues are outside your realm, but I sure would appreciate some assistance considering its inside the unique structure of the theme and its files.
Let me know what you think.
Cheers
David