You can hide certain WooCommerce product categories from the shop page or other targetted pages, by using an action called woocommerce_product_query

Add it in your theme via functions.php and it works like so…

So the action is wrapped in a conditional statement that targets the pages you want the Product Categories to not display.

Then in the $tax_query array set the terms value array to the actual Product Categories you need to be removed.

ref

11 Comments

  1. aaron davis on April 30, 2020 at 1:47 pm

    This helped me so much, easy to setup and do for people with only a little bit of coding knowledge.

  2. nic on October 31, 2019 at 2:12 pm

    does not work!

  3. Mark Simkiss on May 24, 2019 at 4:08 pm

    There is hope! Trying to figure out something that seems easy but I don’t have the expertise. Perhaps it would be easy for you? What I need to do is exclude products in specific categories (or with specific tags) from appearing on the main shop page. I want them show up on the category URL: http://www.website.comm/store/clientname as they are all categorized with “clientname”. Works great. However, they also show up on the main shop page “www.website.comm” from which I would like to hide them. I only want them to show up if you go to the category URL. How would that be done? (also, all without a password/login)

  4. +ES on April 15, 2019 at 7:40 pm

    Hello+

    Thank you very much for posting this information and code! I am very interested in using this, but I have about 50 categories for my bakery shop and I only want to show 1 category on the Shop Page. Is there a way to say “include this 1 category only” instead of “exclude these 49 categories” via code…

    Right now I would have to add all 49 categories and as I make new categories (for new baked goods) I would need to add each of those to the code-list. But, if the code said show one category that would be an easier way for me as I will always want to show only that one category on the Shop page (no matter how many new ones I create).

    I can provide additional information, if you need it. Thank you for your guidance and time on this!

  5. Jonathan on June 13, 2018 at 4:38 am

    Hello. This is great and I really appreciate you sharing.

    One question: I’d like to exclude categories on the ‘products’ page and any subpage of ‘products’, for example ‘products/page/2/’

    Is there a way in the code to target the main page and all child pages?

  6. Luc on April 20, 2018 at 2:22 pm

    How instead of page name “award” can I use the page id?

    • Neil Gowran on April 20, 2018 at 8:55 pm

      Put id number in the parentheses

  7. David Dunnington on April 19, 2018 at 11:50 am

    Was looking for this for quite a while. Worked perfectly thank you.

  8. siyad on February 9, 2018 at 12:57 pm

    its working thanx

  9. Micki on November 23, 2017 at 1:15 am

    Hi, this is not working, though I was excited to find it!

    I replaced:
    if( is_shop() || is_page(‘awards’) ) with is_page(‘my-shop-page’) )

    And replaced/added my category slugs here:
    ‘terms’ => array( ‘cat1’, ‘cat2’ )

    will it only work with new categories created after adding the snippet? thanks!

Leave a Comment