Site icon Experience Wordpress Developer Online – Design Develop and Maintenance Support

Hide particular category on the shop page in woocommerce

First of all create some products and assign them to categories. I’ve created two products, two categories and assigned one product to each category.

This will be my shop page look like after products creation and assignation with the category.

Now, let’s say I want to remove one category i.e. Men Watch from shop page.

You’ll see the defined category has been removed in shop page.

You will need to put this code in your theme’s functions.php file of your active child theme (or theme)


add_action( 'pre_get_posts', 'custom_pre_get_posts' );

 function custom_pre_get_posts( $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( 'mens-watch'), // Replace the category slug of the category in the terms array with the category slug
         'operator' => 'NOT IN'
     )));
  }
remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

 }
Exit mobile version