4 Ways to Hide Categories from WooCommerce Shop Page

4 Ways to Hide Categories from WooCommerce Shop Page

A thriving e-commerce website relies heavily on a user-friendly and well-categorized shop page. In the dynamic world of online shopping, the ability to customize and optimize your shop page becomes crucial. One common requirement is the need to hide specific categories from the shop page in WooCommerce. In this article, we’ll explore four effective ways to hide categories from WooCommerce shop page, catering to different scenarios and user preferences.

Why Hide WooCommerce Categories?

Before diving into the methods, let’s understand why hiding categories from the shop page is necessary. There are several scenarios where this becomes crucial:

  1. Out of Stock or Discontinued Products: If certain products within a category are no longer available or have been discontinued, hiding the category maintains a tidy and organized shop page.
  2. User Role-Based Display: Some shop owners may wish to tailor the shopping experience based on user roles. For example, displaying specific categories only to logged-in customers while keeping them hidden from regular visitors.
  3. Seasonal Categories: In cases where seasonal collections are present, such as summer and winter clothing, hiding irrelevant categories during off-seasons helps streamline the shopping experience.

4 Ways to Hide Categories from WooCommerce Shop Page

1) Hide via PHP Code Snippet

This method is beneficial when you want a lightweight solution that doesn’t involve installing additional plugins. It allows you to customize the visibility of specific categories by adding a simple code snippet to your theme’s function.php file. To hide a category without deleting it, you can employ a PHP code snippet. Follow these steps:

  • Navigate to WooCommerce > Products in your WordPress Dashboard.
  • Identify the category’s slug that you want to hide.  Hide Categories from WooCommerce Shop Page
  • Access Appearance > Theme Editor and locate the theme’s function.php file.
  • Insert the provided PHP code snippet, replacing ‘ADD CATEGORY SLUG HERE’ with your desired category slug.
    add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
    function ts_get_subcategory_terms( $terms, $taxonomies, $args ) {
    $new_terms = array();
    if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() &&is_shop() ) {
    foreach( $terms as $key => $term ) {
    if ( !in_array( $term->slug, array( ' Add CATEGORY SLUG HERE ' ) ) ) { //pass the slug name here
    $new_terms[] = $term;
    }}
    $terms = $new_terms;
    }
    return $terms;
    }
  • Update the file to see the category hidden on the shop page.

2) Hide Based on User Role

If you wish to display certain categories only to logged-in users, use a PHP code snippet. This technique is useful when you want to create a personalized shopping experience based on user roles. By hiding specific categories from non-logged-in users, you can encourage user registration and offer exclusive access to certain products.

If you wish to display certain categories only to logged-in users, use the following PHP code:

  • Add the provided PHP code to the bottom of your function.php file.
    add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
    function ts_get_subcategory_terms( $terms, $taxonomies, $args ) {
    $new_terms = array();
    if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() &&is_shop() && !is_user_logged_in() ) {
    foreach( $terms as $key => $term ) {
    if ( !in_array( $term->slug, array( ' ADD CATEGORY SLUG HERE ' ) ) ) { //Add the slug name here
    $new_terms[] = $term;
    }}
    $terms = $new_terms;
    }
    return $terms;
    }
  • Modify ‘ADD CATEGORY SLUG HERE‘ with the relevant category slug.
  • This code ensures that the specified category is hidden for non-logged-in users.

3) Hide Categories Across the Entire Website

This approach is suitable when you want a comprehensive solution to hide a category’s visibility across your entire website. It ensures consistency by keeping the category hidden in various sections, maintaining a cohesive user experience.

To hide a category not just from the shop page but also from widgets, posts, and all pages, utilize the following PHP code:

  • Add the code to your function.php file as explained earlier.
    add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
    function ts_get_subcategory_terms( $terms, $taxonomies, $args ) {
    $new_terms = array();
    if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() ) {
    foreach( $terms as $key => $term ) {
    if ( !in_array( $term->slug, array( ' ADD CATEGORY SLUG HERE ' ) ) ) { //Add the slug name here
    $new_terms[] = $term;
    }}
    $terms = $new_terms;
    }
    return $terms;
    }
  • This method ensures the category remains hidden across the entire website.

4) Use a Plugin for a Simplified Approach

This plugin offers a straightforward solution without the need for coding skills. It’s ideal for users who prioritize simplicity and ease of use. The plugin streamlines the process, allowing you to hide categories with just a few clicks, making it accessible to a broader audience.

For those who prefer a more user-friendly method, consider using the “Hide Categories Or Products On Shop Page plugin:

  • Install and activate the plugin from the WordPress dashboard. Hide Categories from WooCommerce Shop PageHide Categories from WooCommerce Shop Page
  • Navigate to WooCommerce > Hide Categories or Products to access the plugin settings.
  • Choose the category you want to hide and check the appropriate boxes. Hide Categories from WooCommerce Shop Page
  • This plugin offers a straightforward way to hide categories without dealing with code snippets.

Frequently Asked Questions

Q: How can I hide a category from the WooCommerce shop page?

Install and activate the “Hide Categories Or Products On Shop Page” plugin, navigate to WooCommerce > Hide Categories or Products, select the desired category, and check the “Hide Category” box.

Q: Does WordPress have a built-in feature to hide a category from the shop page?

No, WordPress does not have a built-in feature for this purpose. However, code snippets or plugins can be utilized.

Q: How do I hide multiple categories on the shop page?

Modify the PHP code provided earlier by adding multiple category slugs to the array. This allows you to hide multiple categories simultaneously.

Ending Thoughts

In conclusion, you now possess four versatile methods to hide WooCommerce categories from your shop page. Depending on your preference and technical expertise, choose the approach that best suits your needs. If you encounter any issues or have further questions, feel free to reach out in the comments section. Happy customizing!