• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

OrganicWeb

Mailchimp Training & Consulting

  • Home
  • Services
    • Mailchimp Training
    • Mailchimp Consulting
  • Free Tools
    • Mailchimp Tutorials on YouTube
    • Subject Line Generator
    • Marketing Ideas Generator
    • Map Maker for Email
    • WhatsApp Click to Chat Generator
    • Avoid Email Going to Spam
    • Email Link Generator
    • Is Mailchimp Down?
    • Marketing Facts and Stats
  • Content
    • Blog
    • Videos
  • Contact & About
    • Contact
    • About

WooCommerce – exclude categories from showing

Ecommerce for WordPress
A customer uses WooCommerce to power their online shop. They required a certain category to be available through the WordPress dashboard but the category wasn’t to display on the shop pages or any widgets. Here is the PHP required to achieve the outcomes. Just add the following to your functions.php.

Don’t show WooCommerce category on a page

The following PHP will exclude a category name or thumbnail from showing on your shop and other pages. This script filters the WordPress get_terms function.

add_filter( 'get_terms', 'organicweb_exclude_category', 10, 3 );
function organicweb_exclude_category( $terms, $taxonomies, $args ) {
  $new_terms = array();
  // if a product category and on a page
  if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_page() ) {
    foreach ( $terms as $key => $term ) {
// Enter the name of the category you want to exclude in place of 'uncategorised'
      if ( ! in_array( $term->slug, array( 'uncategorised' ) ) ) {
        $new_terms[] = $term;
      }
    }
    $terms = $new_terms;
  }
  return $terms;
}

Don’t show WooCommerce category in widget

The following PHP will exclude a category name from showing in your category widget. This script filters the WooCommerce woocommerce_product_categories_widget_args hook.

add_filter( 'woocommerce_product_categories_widget_args', 'organicweb_exclude_widget_category' );
function organicweb_exclude_widget_category( $args ) {
// Enter the id of the category you want to exclude in place of '30'
		$args['exclude'] = array('30' );
		return $args;
}

Found this useful? Please share:

Related

  • How to remove cents in Gravity Forms prices
  • Add your own RSS feed to WordPress Dashboard
  • How to get Mailchimp Subscriber Popup working in WordPress

Filed Under: WordPress

Watch Gary in action

Gary frequently adds Mailchimp instructional videos to his YouTube channel. Subscribe to keep updated.

→  Subscribe   ←

How to add an editable attachment to a Mailchimp campaign.

How to add, and send, coupon codes in Mailchimp.

Reader Interactions

Comments

  1. Sandy says

    May 27, 2015 at 12:46 pm

    This code seems to generic. I want some of the categories to show, and some not to show. I don’t see where I need to place the categories I don’t want to show in this code.
    Thanks.

    Reply
    • Gary says

      May 29, 2015 at 9:08 am

      @Sandy, in the code, where it says ” Enter the name of the category you want to exclude in place of ‘uncategorised’ ” enter your comma separated list of categories there

      Reply
  2. Don says

    January 9, 2016 at 6:49 am

    Works Perfect!! Thank you!

    Reply
  3. Kamil says

    January 24, 2016 at 7:52 am

    Hello, how hide category on other pages ex shop, product_category…

    In this code is only: “is_page” … When I add && is_shop etc … don’t work 🙁

    Reply
  4. Emily says

    August 16, 2016 at 1:45 am

    Thank you so much!!!! All the other tutorials I found didn’t work on any page other than the products page – I needed it removed from another page and this worked perfect!E

    Reply
  5. Josh says

    March 30, 2017 at 9:52 pm

    Hello – Could this code be used to hide certain categories for only some user roles?

    Reply
  6. mickofingleton says

    August 31, 2017 at 1:42 am

    Is it possible to use this to hide all categories, thus showing only the product and price. I know you would usually set this in woocommerce but the theme has been tweaked by developer to show product and category in the shop overriding the woocommerce settings.

    Reply
  7. Luke says

    September 30, 2017 at 12:40 am

    Great snippet Gary!

    Can the “don’t show category” snippet hide the entire product list item (li) from the loop for the chosen category? This page in specific: http://stage.lileo.co/best-selling/. Looking to hide all list item products from the “rentals” category (li.product_cat-rental-product or li.product_cat-rentals).

    Thanks for your help!
    Luke

    Reply
  8. francesco says

    October 20, 2017 at 2:10 am

    works only on Home page not in /shop.
    Can you fix it thanks
    F.

    Reply
    • bsamarketing says

      November 2, 2017 at 12:25 am

      if you change the line:

      if ( in_array( ‘product_cat’, $taxonomies ) && ! is_admin() && is_page() ) {

      to read

      if ( in_array( ‘product_cat’, $taxonomies ) && ! is_admin() && ( is_page() || is_shop()) ) {

      That should remove it from the shop page too

      Reply
      • MRN says

        November 20, 2017 at 10:34 pm

        This change did not help, I can see this under /shop/ still

        Reply
        • mrn says

          November 21, 2017 at 10:13 pm

          I had used the category name but should have used the slug … all good. thanks for the article

          Reply
          • Sofia Güerne says

            November 25, 2017 at 5:12 am

            MRN, I am trying to so the same, but with no luck. What code exactly did you use? I want to remove the category thumbnails from appearing in the Shop homepage.
            Thanks!

  9. Avo says

    November 25, 2017 at 1:56 pm

    Great! while many other tips show only how to hide products of a category, this one helped me to hide the category thumbnail!.

    Reply
  10. Rafael Triolo says

    February 1, 2018 at 4:23 am

    Nice code man! I did a little modification, instead of is_page, I used is_product_category(), and instead of $term->slug, I used $term->term_id.

    Tks, I really appriciate.

    Reply
  11. volkerforster says

    February 10, 2018 at 1:50 am

    I just added the code to my website, and the unwanted category “uncategorized” disappeared from the shop home page, indeed. But it is still shown on the category widget in the sidebar or every product detail page. How can I disable this as well? I don’t want to have this unwanted category showing up just anywhere.

    thanks for the code 😉

    Reply
    • Joe Bloggs says

      February 18, 2018 at 3:33 pm

      I’m after the same ..

      Reply
  12. Santon says

    March 29, 2018 at 1:14 pm

    I have a big problem that lasts a few days and I can’t resolve it.
    My site doesn’t display category thumbnails on a shop page, nor does it accept them, although the images are normally uploaded to the gallery. The strange thing is that it has accepted a picture of one category, the rest not, although they are the same size and extension (jpg). I changed the theme, disconnected the plugins, installed the Regenerate Thumbnails plugin, changed Permissions but nothing helped.
    WC version: 3.3.4 WP version: 4.9.4
    Does anyone know how can I resolve this problem?

    Reply
  13. Charlotte Højgaard Jessen says

    March 31, 2018 at 2:12 am

    Sorry – I know you have anwered this already, but I can’t figure out how to hide more than one category. I tried both (‘anledning, kategorier, kollektioner’) and (‘anledning’,’kategorier’,’kollektioner’) – but either way my page goes into failure mode :'(

    Reply
  14. Taussef says

    April 9, 2018 at 7:08 pm

    try this
    add_filter( ‘get_terms’, ‘get_subcategory_terms’, 10, 3 );

    function get_subcategory_terms( $terms, $taxonomies, $args ) {
    $new_terms = array();
    // if a product category and on the shop page
    // to hide from shop page, replace is_page(‘YOUR_PAGE_SLUG’) with is_shop()
    if ( in_array( ‘product_cat’, $taxonomies ) && ! is_admin() && is_page(‘YOUR_PAGE_SLUG’) ) {
    foreach ( $terms as $key => $term ) {
    if ( ! in_array( $term->slug, array( ‘woo’ ) ) ) {
    $new_terms[] = $term;
    }
    }
    $terms = $new_terms;
    }
    return $terms;
    }

    // Replace “woo” with the product category slug of the category you need hidden

    Reply
  15. Panda House says

    June 30, 2018 at 4:30 pm

    Is there a way to hide the product category on a specific time. I don’t want to show the product category or product from 4pm to 10pm. any help? Thank you.

    Reply
  16. doornekamph says

    September 5, 2018 at 5:25 am

    Is there a way to use your code to hide products with a certain “tag” attached to it? so not hide category’s. but hide products based on a tag attached to it.

    Reply
  17. doornekamph says

    September 5, 2018 at 5:27 am

    Yes by setting this piece of code in an If statement “if time = between .. and .. then run the script of the example” (and then in good PHP ofcourse)

    Reply
  18. jasonearrame says

    October 4, 2018 at 8:13 am

    Hello, I have been hitting my head against this for a while and have tried 3 or 4 different snipits that have been posted. I just tried the one above to remove one category (ethnic-ornaments) from dev-wp.ornaments.com/shop. I replaced is_page with is_shop. I have tried using the category slug and its ID. I am just stuck. Nothing I have tried works. Can you point me in a direction that will help?

    Reply
  19. rick nash says

    January 13, 2019 at 11:36 am

    the only way i cant get this to work is to use the following code

    add_filter( ‘get_terms’, ‘organicweb_exclude_category’, 10, 3 );
    function organicweb_exclude_category( $terms, $taxonomies, $args ) {
    $new_terms = array();
    // if a product category and on a page
    if ( in_array( ‘product_cat’, $taxonomies ) && ! is_admin() &&
    is_product_category() ) {
    foreach ( $terms as $key => $term ) {
    // Enter the name of the category id you want to exclude in place of ”
    if ( ! in_array( $term->term_id, array( ‘112’ ) ) ) {
    $new_terms[] = $term;
    }
    }
    $terms = $new_terms;
    }
    return $terms;
    }

    my problem is i still want it to show in the widget in the side bar which it isn’t any help be great

    Reply
  20. davideschiano2015 says

    May 23, 2019 at 8:55 pm

    Thanks so much ! It works perfectly !

    Reply
  21. Martin V says

    July 17, 2019 at 8:42 pm

    by slug on latest Woo did not work, but above works fine

    Reply
  22. Armando Rendon says

    December 16, 2020 at 8:09 am

    Rick Nash answer worked for me after several hours. I had to use several two codes since it does not appear from other categories or sub-categories. Using shop code and Nash code does work.

    add_filter( ‘get_terms’, ‘organicweb_exclude_category’, 10, 3 );
    function organicweb_exclude_category( $terms, $taxonomies, $args ) {
    $new_terms = array();
    // if a product category and on a page
    if ( in_array( ‘product_cat’, $taxonomies ) && ! is_admin() &&
    is_product_category() ) {
    foreach ( $terms as $key => $term ) {
    // Enter the name of the category id you want to exclude in place of ”
    if ( ! in_array( $term->term_id, array( ’91’ ) ) ) {
    $new_terms[] = $term;
    }
    }
    $terms = $new_terms;
    }
    return $terms;
    }

    add_filter( ‘get_terms’, ‘ts_get_subcategory_terms’, 10, 3 );
    function ts_get_subcategory_terms( $terms, $taxonomies, $args ) {
    $new_terms = array();
    // if it is a product category and on the shop page
    if ( in_array( ‘product_cat’, $taxonomies ) && ! is_admin() &&is_shop() ) {
    foreach( $terms as $key => $term ) {
    if ( !in_array( $term->slug, array( ‘cursos-presenciales’ ) ) ) { //pass the slug name here
    $new_terms[] = $term;
    }}
    $terms = $new_terms;
    }
    return $terms;
    }

    Thanks for support.

    Reply

Leave a Reply Cancel reply

You are here: Home / WordPress / WooCommerce – exclude categories from showing

Primary Sidebar

Mailchimp write about my work

Read on Mailchimp.com

Learn from a Mailchimp Pro Partner

Signup to receive info about Gary's Mailchimp beginner and advanced classes.

Sign up

Gary on Australian National Radio

Changes are coming to the Australian Spam Act

Read Gary's article in SmartCompany

Meet Gary, Mailchimp Expert

Gary is a Mailchimp Expert and Partner. He delivers Mailchimp training and consulting services in Australia, New Zealand and Singapore. Gary presents at Mailchimp events and hosts the first, and only, Australian Mailchimp sponsored event. He is M.B.A. qualified from Henley Business School, U.K.

Contact Gary for your Mailchimp needs

Footer

Customer Rating

Mailchimp Pro Partners

Contact

Contact Gary for all your Mailchimp training, consulting and integration needs.

Contact Gary.

Copyright © 2022 · Sitemap · ABN: 40800872179 · Privacy Policy · Terms of Service