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.