Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to hide WooCommerce Categories from being displayed on Shop page

How to hide WooCommerce Categories from being displayed on Shop page | tychesoftwares.com

The Shop page is one of the most important pages on the E-Commerce website. Since the consumers can’t physically view what all products you are selling, it is very important to present a shop page in a way to make it easier for them to stay on the website and make a purchase decision.

This post is specifically for those who have built up the stores using the WooCommerce plugin. In this post, we will see how to show all product categories on shop page using WooCommerce customizer and how to hide WooCommerce categories from being displayed on the shop page.

WooCommerce lets you decide how you want your products to be displayed on a Shop page. Using Product Catalog under Appearance-> Customize->WooCommerce you can show the WooCommerce Shop page in a unique manner. For example, you can display only category, the category with products or only products.

  • Show products: All the product will be listed.
  • Show categories: All the categories will be listed
  • Show categories and products: Products and Categories both will be listed.
WooCommerce Product Catalog - hide woocommerce categories
WooCommerce Product Catalog

If we select ‘Show categories‘ option under ‘Shop page display‘ then all the product categories will be displayed on the Shop page as shown in the below screenshot.

Categories on Shop page - hide woocommerce categories
Categories on Shop page

As you can see in the above screenshot, four categories are being listed on the Shop page. The first one is ‘Uncategorised’ category, which contains all the products that don’t have any category assigned then it will be considered in the ‘Uncategorised’ category. Other categories are Men, Women, Kids & Baby.

Hide a WooCommerce Category from Shop Page

In some scenarios, you don’t want to display some categories on the Shop page. Like the ‘Uncategorised’ category appearing on the shop page and that is ruining the presentation of it. Either by giving the correct name to this category or by hiding it from being listed on the Shop page the presentation of the shop page can be improved.

So let’s see how to hide WooCommerce categories from being displayed on Shop using a small piece of code as shown below.

I have added this code snippet in my currently active theme’s functions.php file. The magic of this code snippet is, it has removed the ‘Uncategorised’ category being displayed from the shop page as shown in below screenshot.

Shop page without Uncategorised - hide woocommerce categories
Shop page without Uncategorised

 

Important: Even though the category is being hidden from Shop page, but it is still accessible via URL.

In WordPress, a “taxonomy” is a grouping mechanism for some posts (or links or custom post types). The names for the different groupings in a taxonomy are called terms. For example, ‘product_cat’ is the taxonomy to categorize the products in the WooCommerce.

WordPress provides a filter hook called get_terms to modify the term data and using this filter I have modified the display of WooCommerce category on the Shop page.

Paramaters of get_terms filter hook are:
$terms (array) Array of found terms.
$taxonomies (array) An array of taxonomies.
$args (array) An array of get_terms() arguments.
$term_query (WP_Term_Query) The WP_Term_Query object.

Let’s see step by step what exactly I have done in the code snippet to hide WooCommerce category.

In the callback function get_subcategory_terms()  I have initialized a variable $new_terms with an empty array which will be used later to create an array of WooCommerce categories to be displayed on the shop page.

Then I have initialized the $hide_category variable with the arrays of category ids which I don’t want to display on the shop page. Here you can set IDs of the category you want to hide on your shop page.

After that, I have checked if the ‘product_cat’ is present in $taxonomies or not, and checked if it is front end page and shop page then only execute the actual modification part. Using is_admin() function we can check if it is a front end or the admin end. And using is_shop() function we can check if it is WooCommerce Shop page or not.

Once all conditions are true, then using foreach loop I have the looped through $terms data for preparing new term data in $new_terms variable. The $new_terms variable will not have the term data of the WooCommerce category we want to hide on the Shop page. For each term data, I am checking if the term id is not present in a $hide_category array then only add the term in the $new_terms array.

Once looped through all the data then finally, I have assigned the $new_terms data to $terms and returned the modified terms data. So the data for Men, Women, Kids & Baby category will be passed to display on the shop page.

Add this small piece of code in your currently active theme’s functions.php file and in the code snippet, add the IDs of categories you don’t want to display on the Shop page. This code snippet can be used as a skeleton which can be improved more with some extra code and conditions as per the different scenarios. E.g you can hide some product categories for guest users or you can hide the categories based on the role of the user.

The idea of writing this post came to my mind when one of our clients asked for the customization in our Booking & Appointment Plugin for WooCommerce. What he wanted was, when searching for the available products along with particular category using our Booking & Appointment Availability Search widget and if the shop page view is set to Show categories then, the search result should display selected category.

Conclusion

In this post, we have seen that how to change the view of shop page to list the product categories and hide a particular WooCommerce category from being displayed on Shop page using a small piece of code.

There might be many other scenarios to hide the products and categories from being listed on the shop page so by adding some more code in the elaborated code snippet you can achieve your requirements.

Feel free to mention your questions in the comments below and we shall get back to you as early as possible.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

69 thoughts on “How to hide WooCommerce Categories from being displayed on Shop page

  1. Hello friends
    I need to change the product category page from the default and create a new page for it myself, because I have a multilingual site and the problem is that the header section of the site theme cannot be translated and it must be done manually on the pages of this topic. to be
    All pages have been changed, only the problem is with the product category page

  2. Hi! I used the code and it removed the categories from my individual product posts. Awesome!

    My other problem that I cannot find an answer for, is that on the shop’s main page, where it populates the products, every one has a glaring “UNCATEGORIZED” (which is all of them). Any idea how I get this to quit displaying? I’ve been beating my head against the wall for days!

  3. That’s great and all but WHERE do you call this function? I think you left this rather important detail out of your otherwise well explained post.

  4. Hi KartikI will ask you this maybe a little off-topic: I created many categories by product brand in order to aggrupate in several brand pages, the corresponding products, but my customer does not whant to see this categories, only the ones that correspond to his Categories structure, is there any way to hidden those particular categories? WooCommerce.

  5. THANK YOU, it worked at first try. You’ve saved me a lot of time. I’ll check on your page if I can purchase something

    1. Hi Nisaza,
      I am glad to know that. 🙂
      I’ll check on your page if I can purchase something
      : That’s great. Feel free to let us know if you need any help with the purchase.

  6. Hi,

    I hope that you are doing good. Thank you for the precious information.

    I tried your code, but I was getting an error on the shop page.

    Can you let me know what can be the reason of the error?

    Notice: Trying to get property ‘object_id’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 3533

    Notice: Trying to get property ‘taxonomy’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 3533

    Notice: Trying to get property ‘term_id’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 3533

    Notice: Trying to get property ‘object_id’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 3533

    Notice: Trying to get property ‘taxonomy’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 3533

    Notice: Trying to get property ‘term_id’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 3533

    Notice: Undefined index: term_id in C:\xampp\htdocs\wordpress\wp-includes\class-wp-list-util.php on line 161

    Notice: Trying to get property ‘term_id’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 4578

    Notice: Trying to get property ‘name’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 4582

    Notice: Trying to get property ‘slug’ of non-object in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 4585

    Notice: Array to string conversion in C:\xampp\htdocs\wordpress\wp-includes\taxonomy.php on line 975

    Warning: ltrim() expects parameter 1 to be string, object given in C:\xampp\htdocs\wordpress\wp-includes\formatting.php on line 4309

    Notice: Trying to get property ‘term_id’ of non-object in C:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce\includes\wc-template-functions.php on line 2513

    Notice: Trying to get property ‘name’ of non-object in C:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce\includes\wc-template-functions.php on line 2535

    1. Hi Ziyam,
      I apologize for the late response.
      I have checked the code once again to see if the same issue occurring for me or not. Unfortunately, things are working fine on my end. I have only the WooCommerce plugin and Storefront theme active on my site. Can you please check once with only WooCommerce Plugin and Storefront theme active? Please let me know the result.

    1. Hi Ahmet,
      Yes, it still works.
      There might be some conflict that could cause the snippet not to work. Kindly check once with only WooCommerce Plugin and Storefront Theme active and let me know the result.

  7. Hi thank you for this, it’s a start. It works for /shop, but if user clicks on one of the categories that I do want to display, they can now see the hidden ones again.

    Example: “hidden” is a category I don’t want them to see. “Good” is a category I do want them to see.

    I hide “hidden” from main shop page – domain.com/shop – using snippet, it works.

    But if user clicks on the category “good”, it takes them to:

    domain.com/product-category/good/

    Now they can see “hidden” again. Is there a way to hide them from there too? Or is that only specific to my theme?

  8. Thanks for your useful guide. Should I edit my theme’s functions.php file directly? I’m afraid the new code will be gone once we update the theme.

  9. Hi,

    Could you please advise how to change the snippet for hiding certain categories from product pages (and not just from the shop page)?

    Thank you and kind regards,
    Attila

    1. Hi Attila,

      Can you please let me know how and where exactly the categories being displayed on the product pages?

      1. Hi Kartik, Thank you for the response. I finally realized that I do not need to hide categories from the archive page but from the product pages. I found therefore a different solution for that.
        Attila

  10. Hi,

    I have a question what is a littlebit different from this code but i hope you can help me.

    I want to show 6 products in a catagorie to only one user role… and for that particular role its okay they see all the products on the website.

    The rest of the user roles can see all of the products minus the 6 products in the category.

    Because its only for this 6 products.. i want to do this with some code in my functions.. but i cannot find it.

    Do you know a sollution?

    1. Hi Jap,

      It will be custom work and that will be chargeable. If you are interested then feel free to drop an email on the below email address.
      Email Address: kartik at tychesoftwares dot com

  11. This only hides a parent category when there are sub-categories in the Parent. How do you hide the Parent AND all sub-categories of a parent category without having to add all ids of all categories to the array?

        1. Hi David,

          I am glad to know that it worked for you. 🙂

          Please let me know if you need any further assistance.

          : Kartik

  12. Hello i need hide the Food category on my shop page and i have just write this in my theme’s functions.php file
    $new_terms = array();
    $hide_category = array( 1913 ); // Ids of the category you don’t want to display on the shop page

    but in my site have error, can you please tell me how rigth need write the code for it work?

    1. Hi Nazir,

      I am assuming that you have added only these two lines of code in your functions.php file. If that is the case, then first of all you have to use the complete code which is provided in this post and just have to replace the category ids. Even if you have added only those lines of code then I am wondering why it should throw any errors. Kindly share the error message so that I can get back to you with the optimal answer.

        1. Hi Nazir,

          Thank you for sharing the screenshot and link to your website.

          The code is correct but I am not sure why it is not excluding ‘Food category’ from the shop page. It would be great if you can check the same code in Storefront theme. If things are working fine on the Storefront theme then please contact your theme author about this issue. They will help you better in this matter.

          1. Hi Nazir,

            I have tested the same code in Twenty Nineteen theme and the same is working fine for me. Hoping that the category id you have used is correct one. Please verify that and let me know.

  13. Thanks for taking the time to post this. I would like to hide a category from the main shop page of my site. My struggle with this code is that I can’t find IDs for the categories, only for the products. Am I misunderstanding something? Also, if I use this code (assuming I can find IDs for the categories!) if a user goes directly to the category via a link, will they see the products in that category? That’s what I’m hoping for, thanks!

  14. Hi Kartik,
    unfortunately I get a Warning when using your code.
    It says:
    Warning: in_array() expects parameter 2 to be array, null given in /www/htdocs/…/…/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code on line 12

    Do you have an idea how to solve that?
    Thank you so much!

    1. Hi Hanna,

      Thank you for sharing the error message. I am assuming you are trying to modify the code according to your business requirements and facing this issue. The error message says that the second parameter used in ‘in_array’ PHP function is null whereas it should be array. Kindly verify if the variable passed in the second parameter of the in_array function is an array or not. Make changes accordingly.

      Feel free to let me know if you need any assistance.

      1. Hello Kartik – Thank you for this code!!!

        I am also getting this warning “parameter 2 to be array, null given in /home/bearnece/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code on line 10”

        Here is the code exactly as I have put it in:

        /**
        * Show products only of selected category.
        */
        function get_subcategory_terms( $terms, $taxonomies, $args ) {

        $new_terms = array();
        $hide_category = array( 92 ); // Ids of the category you don’t want to display on the shop page

        // if 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->term_id, $hide_category ) ) {
        $new_terms[] = $term;
        }
        }
        $terms = $new_terms;
        }
        return $terms;
        }
        add_filter( ‘get_terms’, ‘get_subcategory_terms’, 10, 3 );

        1. Hi Halee,

          I am using Storefront theme on my test environment and the same code is working fine at my end. The issue could be with your currently active theme. So it would be great if you can switch the theme to Storefront and check once how it goes. If the code works fine in Storefront theme then please contact the theme author in which you are facing the issue.

          Please let me know if you need any further assistance.

    1. Hi Chris,

      I am glad to know that you are able to implement this snippet on your website and it works fine for you. 🙂

    1. Hi Carla,

      I am glad to know that the information which I have shared via this post was helpful to you. 🙂 Please let me know if you need any further assistance.

      : Kartik

  15. Hi, I would like to remove all categories fullstop. We have only a few products, all in the same category, so the category is redundant. Do you know how to remove any category from displaying below a product. So there is the product image only? thanks

    1. Hi Brett,

      Can you please share the URL of your website so that I can try to understand what exactly you are trying to achieve?

      1. Hi, I just reinstalled the template to the website as I’d mucked it up with various changes, so this is the straight template: https://dev.atuanuipress.co.nz/dir3/ if you scroll down or go to the store page you’ll see every item is listed with its category, either ‘men’ ‘women’ ‘accessories’ or ‘uncategorised’. I would like no category to show up under any item. On our website when its done all the items will be books, so I don’t need to say ‘books’ under them. So I would like simply no category listed beneath any item’s picture. thanks, Brett

        1. Hi Brett,

          Thank you for sharing the URL. You can hide it using CSS code. Please use below CSS code and let me know if that works for you or not.

          CSS code:

          .ast-woo-product-category {
          display: none !important;
          }

          1. Hi Brett,

            I am glad to know that the provided CSS code working fine. 🙂 Feel free to let me know if you need any further assistance.

            From the website URL which you shared earlier, I noticed that you are doing clothing and accessories business. I would recommend our “Abandoned Cart Pro for WooCommerce” plugin which gives store owners the ability to recover sales that are lost to abandoned shopping carts by logged-in customers or by visitors. Also, feel free to explore our plugins.
            Link: https://www.tychesoftwares.com/premium-woocommerce-plugins/

            : Kartik

          2. Here is a variation of code which removes category from all pages which are based on WooCommerce templates:

            /**
            * Show products only of selected category.
            */
            function get_subcategory_terms( $terms, $taxonomies, $args ) {

            $new_terms = array();
            $hide_category = array( 59 ); // Ids of the category you don’t want to display on the shop page

            // if a product category and on the shop page
            if ( in_array( ‘product_cat’, $taxonomies ) && !is_woocommerce() ) {
            foreach ( $terms as $key => $term ) {
            if ( ! in_array( $term->term_id, $hide_category ) ) {
            $new_terms[] = $term;
            }
            }
            $terms = $new_terms;
            }
            return $terms;
            }
            add_filter( ‘get_terms’, ‘get_subcategory_terms’, 10, 3 );

          3. Hi Nick,

            Right. Instead of “is_shop()” function, using ” !is_woocommerce()” in if condition will remove the categories from all pages which are based on WooCommerce Template. Thank you for sharing the information.

          4. Thanks for the information… It works for me… By replacing is_shop with is_woocommerce hide the category from all the pages…
            Thanks again…

          5. Hi,

            I am glad to know that it works for you. 🙂 Please let me know if you need any further assistance.

  16. Hello! Thank you for a very nice post!! I was wondering, is the requirement for the above code to work that Categories are being displayed on shop page, rather than Products? My shop page displays Products, and I would like to hide products that have been assigned to a particular category. Sadly, I cannot get this work.

  17. There is no PRODUCT CATALOG option for me in WOOCOMMERCE settings.
    I have tried going through the customizer, there is no option.

    I want to view categories on shop page.
    I am using oceanwp theme.

    1. Hi Roopesh,

      I am assuming that you are using OceanWP theme which is freely available on the WordPress Repository.
      Link: https://wordpress.org/themes/oceanwp/

      If yes, then you can go to Appearance-> Customize-> WooCommerce-> Archives. Here you will see Shop page display option.
      Please see this screenshot: https://prnt.sc/m7bhoj

      I hope that is the option you are looking for. Please let me know if you have any further questions.

      : Kartik

  18. I would like to exclude 2 categories from the shop page – ids 31 and 32. I have tried playing with the line :
    $hide_category = array( 31 ); // Ids of the category you don’t want to display on the shop page
    but I have not been able to figure out how to add a second category id correctly in this line. Would it be possible for you to provide an example with hiding 2 categories ?

    1. Hi,

      You can add multiple category ids as follow.
      $hide_category = array( 31, 32 );

      Please check and let me know if that works for you or not.

      : Kartik

      1. Thanks !
        If I just put $hide_category = array( 31 );
        it hides that category,
        but if I put $hide_category = array( 31, 32 );
        it hides both categories ( I only have 2 categories listed on the shop page and I want to hide both of them ), but instead puts all my products paginated (over 18000) on the shop page. Perhaps it is not possible to hide both categories so there is none at all. Maybe some css solution would work instead….

        1. Hi,

          Ok, then you can hide it using CSS code. Go to Appearance-> Customize-> Additional CSS and place below CSS code and click on Publish button.

          CSS Code:
          ul.products {
          display:none;
          }

          Please let me know if that will help or not.

          : Kartik

          1. Hi
            Thanks again – unfortunately that also removes the subcategories on my categories pages. I only want the categories removed on my home/shop page.

          2. Hi,

            Ohh I see. Sorry, I am out of idea now. Please let me know if you find any solution to achieve your requirement so that if someone else comes with a similar query then I can recommend your solution to them. Thanks in advance.

            Please let me know if you have any further questions.

            : Kartik

  19. I don’t want categories or products to show on the shop page. I created a shop page with various products that are not in the woocommerce products because some of those products need to be called in. So I created a shop page with images to various pages of the product including an image that leads to the category page of my products in woocommerce. But when I use the script, the products show up on the shop page. I don’t want the products to be shown. Can you please show me how to hide the products from the shop page?

  20. I tried plugging this code snippet into our page to hide a category “Legion made” and it’s not working. Not sure why.
    The category exists because we produce 95% of our products but the other 5% come from an outside vendor. For royalty reports we need to track the items that we produce. But I don’t have any reason to display that category to end users.

    1. Oops, I noticed my mistake. The code is designed to remove that category from the shop page and I was looking at other pages. Going to see if I can get it to remove from those pages now. It was working on the Shop page.

      1. Hey Geoff,

        I apologize for the late response.

        Yes, this post is all about removing a particular category from being displayed on the Shop page. From your last response, it seems that this post was not the one which you were looking for.

        Can you please let me know you are able to achieve the thing you were looking for? Is there anything I can help you with? Feel free to let me know.

        : Kartik

Leave a Reply to Amy Cancel reply

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

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.