Hide Specific Categories on WooCommerce Shop Page

Sometimes you want to keep certain product categories hidden from your WooCommerce shop page. Instead of removing them, use this handy PHP snippet to filter them out easily.

Code to Filter Product Categories on Shop Page

function filter_shop_page_categories( $query ) {
    if ( is_shop() ) {
        $categories_to_hide = 'your-category-slug'; // Change this to the slug you want to exclude

        $tax_query = (array) $query->get( 'tax_query' );

        $tax_query[] = array(
            'taxonomy' => 'product_cat',
            'field'    => 'slug',
            'terms'    => array( $categories_to_hide ),
            'operator' => 'NOT IN',
        );

        $query->set( 'tax_query', $tax_query );
    }
}
add_action( 'woocommerce_product_query', 'filter_shop_page_categories' );

Things to Keep in Mind

  • This does not block direct access to the products.
  • Only affects the main shop display — not archives or search results.
  • Always back up your site and use a child theme for safety.

You can find more advanced customization options in the WooCommerce query documentation.

Leave a Comment

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.