Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More โRemove specific product categories from WooCommerce shop page without deleting them using woocommerce_product_query hook and tax_query parameters. Control which categories display on shop page, exclude multiple categories, implement conditional category visibility based on user roles or other criteria. Products remain accessible via direct URLs while hidden from shop listings for cleaner shop organization and better user navigation.
Need to remove certain product categories from your WooCommerce shop page? Instead of deleting them, you can tweak your product queries using the woocommerce_product_query hook. This is a safe and flexible way to control product visibility on your shop page.
Steps to Exclude Product Categories
Add the following code snippet to your child theme’s functions.php file:
function custom_exclude_category_from_shop( $q ) {
if ( is_shop() ) {
$exclude_category = 'your-category-slug'; // Replace with your actual slug
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( $exclude_category ),
'operator' => 'NOT IN',
);
$q->set( 'tax_query', $tax_query );
}
}
add_action( 'woocommerce_product_query', 'custom_exclude_category_from_shop' );
How It Works
The code hooks into the WooCommerce product query, excluding products that belong to a specific category. Just update the slug with the category you want hidden.
Important Notes
For advanced filtering options, refer to the official WooCommerce documentation.
Final Thoughts
Controlling product visibility helps streamline your shop layout. With a small code tweak, you can manage how categories appear and improve user navigation. 
Search our archives or reach out to our team for solutions and expert advice.