Cleaning Up Your Storefront: Hiding Specific Categories

By default, WooCommerce displays products from every category on your main shop page. However, you might want to exclude categories like "Add-ons," "Wholesale," or "Internal Parts" from the general public view. Instead of complex template overrides, you can use the `woocommerce_product_query` action. This allows you to inject a `NOT IN` operator into the taxonomy query, ensuring that products belonging to specific slugs are filtered out of the loop while remaining accessible via direct links or search if needed.

Hide Specific Categories on WooCommerce Shop Page

Woocommerce Woocommerce Hooks Wordpress WordPress Development WordPress Functions WordPress How-To WordPress Theme Development WordPress Tutorials WP Hooks

Hide Specific Categories on WooCommerce Shop Page Tutorial/Guide

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.

๐Ÿ’ก Have a Coding Problem?

Search our archives or reach out to our team for solutions and expert advice.