5th Year Anniversary Super Sale! Save Upto 50% OFF*

How to hide a particular product category from shop page in woocommerce?

By

If you want to hide a particular product category to your shop page but many products are available under the product category that means you can use this code to hide a particular category that what you need.

Put this code into functions.php.,


// Remove category slug from shop
 
add_action( 'pre_get_posts', 'remove_cat_from_shop_loop' );
  
function remove_cat_from_shop_loop( $q ) {
  
    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;
     
    if ( ! is_admin() && is_shop() ) {
  
        $q->set( 'tax_query', array(array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array( 'e-books' ), // Change it to the slug you want to hide
            'operator' => 'NOT IN'
        )));
     
    }
  
    remove_action( 'pre_get_posts', 'remove_cat_from_shop_loop' );
  
}

You can change the product category by using the slug.

Tagged under:

Show Buttons
Hide Buttons