T
T
TigNewStyle2018-03-12 13:23:54
WordPress
TigNewStyle, 2018-03-12 13:23:54

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
5aa6551eae5e5500542082.png5aa6552775e6b984280404.png5aa655305da25210703365.png
, 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

1 answer(s)
A
Anton Drobyshev, 2018-03-13
@antoshadrobyshev

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 question

Ask a Question

731 491 924 answers to any question