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 thoughts on “How to exclude one or more category in woocommerce shop page

  1. 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?
    thanks!

    • Arni Cinco

      Hi Julia ,

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

  2. 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

    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’

    to

    ‘operator’ => ‘IN’

    • Arni Cinco

      You are welcome! Thanks for the contribution.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

clear formSubmit