Answer the question
In order to leave comments, you need to log in
How to Hide Certain WooCommerce Categories in the Store?
I hid the category definition from the main page of the store, and the category that I hid added to a separate page, everything works fine as I wanted, but when I click on the category, the page opens and says that there are no products
, here is the code from which I hid
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'cups' , 'souvenirs'), // 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' );
Answer the question
In order to leave comments, you need to log in
Do an is_shop check in a function. Products will hide on the main page and should appear in the categories.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question