How to exclude one or more category in woocommerce shop page

Here’s how to exclude one or more category in your woocommerce shop page. This way you can hide products that are packages or subscription which belong to a page or has its own page. This is tested in Woocommerce 2.0 and WordPress 3.6.

Add this in your current theme functions.php

add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

function custom_pre_get_posts_query( $q ) {

if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() ) {

$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'PUT YOUR CATEGORY HERE' ), // Don't display products in the membership category on the shop page . For multiple category , separate it with comma.
'operator' => 'NOT IN'


remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );


This will work in older version :
Exclude product category in older version of woocommerce.


8 Responses to “How to exclude one or more category in woocommerce shop page”

  1. September 26, 2013 at 9:46 pm

    I keep seeing this code for excluding a category, but not one person says where to put it!
    I have never edited the woocommerce php files before so could you give me a bit more direction?

    • Arni Cinco
      September 28, 2013 at 2:53 am

      Hi Julia ,

      It should be pasted in your current theme functions.php . I already updated the post. Thank you

  2. September 27, 2013 at 1:28 pm

    I’ve tried this but it didn’t work. I’m using woocommerce and woo artificer theme for my shop. Trying so many codes to exclude the category from my shop page but no result. Could you give me some advice?

  3. Tracey
    November 6, 2013 at 12:12 am

    Thanks for this! Worked perfectly.

    Actually it works in reverse as well, just in case anyone wants to display only certain categories, rather than exclude, just change

    ‘operator’ => ‘NOT IN’


    ‘operator’ => ‘IN’

    • Arni Cinco
      November 6, 2013 at 3:08 am

      You are welcome! Thanks for the contribution.

Leave a Reply