WooCommerce: How to Hide a Category (The Easy Guide for Beginners)
So, you’re running a WooCommerce store and need to hide a category? Maybe it contains products that are seasonal, temporarily out of stock, or exclusive to a specific membership group. Whatever the reason, hiding Check out this post: Woocommerce How To Do Percent Off Sale a category can be a smart way to improve your customer experience and streamline your product offerings.
Don’t worry, you don’t need to be a coding wizard! This guide will walk you through several methods, from the simplest to slightly more advanced, allowing you to choose the one that best suits your comfort level and needs.
Why Hide a WooCommerce Category?
Before we dive into the “how,” let’s quickly recap why you might want to hide a category in the first place:
* Seasonal Products: Think Christmas decorations in July. Hiding the category prevents confusion and a less-than-ideal user experience.
* Out of Stock Items: No one likes seeing products they can’t buy. Hiding the category while you restock prevents frustration and redirects users to available items. Imagine a category called “Limited Edition Gadgets” where everything is sold out. Better to hide it than to show empty shelves!
* Members-Only Content: Maybe you offer exclusive products to paying members. Hiding the category from the general public adds Check out this post: How To Install Github.Com Wp-Premium Woocommerce-Subscriptions a layer of exclusivity.
* Simplifying Navigation: A cluttered menu can overwhelm customers. Hiding categories that are rarely used or under development can improve navigation.
* Product Launch Preparation: Before officially launching a new product line, you might want to create the category and populate it with products, but keep it hidden from the public until launch day.
Method 1: The “Unpublish” Approach (Simplest, but Limited)
This is the simplest method, but it’s important to understand Explore this article on How To Use Woocommerce 2019 its limitations. You can’t directly “hide” a WooCommerce category Explore this article on How To Add Php To Top Of Categories Woocommerce Page through the WordPress admin panel in the way you might expect. Instead, you hide the *products* within the category by unpublishing them.
How it works:
1. Go to Products > All Products in your WordPress dashboard.
2. Filter the products by the category you want to “hide.” (Look for the category filter at the top of the product list).
3. Select all the products in that category.
4. In the “Bulk Actions” dropdown, choose “Edit” and click “Apply.”
5. Change the “Status” to “Draft” and click “Update.”
Why it’s limited:
* Time-consuming for large categories: Manually setting each product to draft can be tedious.
* Doesn’t *really* hide the category: The category page itself might still be accessible if someone knows the direct URL (e.g., `yourstore.com/product-category/hidden-category/`). Plus, it’s bad practice to unpublish many of products. It can have an SEO negative effect.
* Product Specific: You are hiding the products and not the category.
When to use it:
* For small categories with only a few products.
* When you need a quick, temporary fix.
* If you just need to hide products and do not care about SEO issues.
Method 2: Using a Category Visibility Plugin (Recommended)
This is the recommended approach for most users because it offers a balance of simplicity and control. Several plugins are available that allow you to hide categories directly from your store’s front end.
Example:
* WooCommerce Category Visibility: Many plugins offer this functionality. Just search in WordPress repository for “woocommerce hide category”
How it works (Generic Steps – varies slightly per plugin):
1. Install and activate your chosen WooCommerce Category Visibility plugin.
2. Go to Products > Categories in your WordPress dashboard.
3. Edit the category you want to hide.
4. You should see a new option provided by the plugin (usually a checkbox or dropdown) to “Hide this category.”
5. Save your changes.
Why it’s better:
* Direct Control: You’re hiding the *category* itself, not just the products.
* Easy to Manage: Simple checkboxes or dropdowns make it user-friendly.
* More Comprehensive: Plugins usually handle hiding the category from menus, shop pages, and search results.
* SEO Friendly: Hides the category without unpublishing products, which can be beneficial for SEO.
When to use it:
* When you need a reliable and easy way to hide categories.
* For more permanent hiding solutions.
* When you want to ensure the category is hidden from all areas of your store.
Method 3: Code Snippet (For the Slightly More Adventurous)
If you’re comfortable adding code snippets to your WordPress theme’s `functions.php` file (or better yet, using a code snippet plugin), this method offers a custom solution.
Important: Always back up your website before editing code. Errors Learn more about How Do You Add Ratings To Your Woocommerce in your `functions.php` file can break your site. Use a child theme or a code snippet plugin to avoid losing your changes during theme updates.
Example Code Snippet:
/**
- Hide specific category from WooCommerce shop page and category archives.
- * @param WP_Query $query The main WordPress query.
- @return WP_Query
if ( ! is_admin() && $query->is_main_query() ) {
if ( is_shop() || is_product_category() ) {
$query->set( ‘tax_query’, array(
array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘slug’,
‘terms’ => array( ‘hidden-category-slug’ ), // Replace ‘hidden-category-slug’ with the actual slug of your category
‘operator’ => ‘NOT IN’,
)
) );
}
}
return $query;
}
add_filter( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );
Explanation:
1. `custom_pre_get_posts_query( $query )`: This function filters the main WordPress query before it’s executed.
2. `if ( ! is_admin() && $query->is_main_query() )`: This ensures the code only runs on the front end of your website and only affects the main query.
3. `if ( is_shop() || is_product_category() )`: This limits the code to only affect the main shop page and product category archive pages.
4. `$query->set( ‘tax_query’, … )`: This part is where the magic happens. It adds a tax query that *excludes* the specified category.
* `’taxonomy’ => ‘product_cat’` specifies that we’re working with product categories.
* `’field’ => ‘slug’` indicates that we’re using the category slug to identify the category.
* `’terms’ => array( ‘hidden-category-slug’ )` is where you replace `’hidden-category-slug’` with the *actual* slug of the category you want to hide. You can find the category slug when editing the category in the WordPress admin.
* `’operator’ => ‘NOT IN’` tells WordPress to exclude any products belonging to the specified category.
How to use it:
1. Find the category slug: Go to Products > Categories, edit the category you want to hide, and look at the “Slug” field.
2. Replace `’hidden-category-slug’` in the code snippet with the actual slug of your category.
3. Add the code snippet to your `functions.php` file (using a child theme) or a code snippet plugin.
4. Clear your website’s cache (if you’re using a caching plugin).
Why it’s more advanced:
* Requires coding knowledge: Understanding PHP and WordPress hooks is helpful.
* Potential for errors: Mistakes in the code can break your website.
* More manual maintenance: If you change categories often, you’ll need to update the code snippet.
When to use it:
* If you’re comfortable working with code.
* If you need a highly customized solution.
* If you want to avoid using plugins.
Method 4: CSS (Simple but Can Be Circumvented)
You can use CSS to visually hide the category from some areas of your website, like menus. This is not a secure method as users can still access the category by directly entering the URL. This method hides the category but the URL is still working.
How it works:
1. Inspect Element: Using your browser’s developer tools (right-click on the element you want to hide, and choose “Inspect” or “Inspect Element”), find the CSS class or ID associated with the category link in your menu or on the shop page.
2. Add CSS Rule: Add the following CSS rule to your theme’s `style.css` file or through the WordPress Customizer (Appearance > Customize > Additional CSS):
.category-id-123 { /* Replace .category-id-123 with the actual CSS class or ID */
display: none !important;
}
Replace `.category-id-123` with the actual CSS class or ID you found in step 1.
Why it’s less ideal:
* Not Secure: The category is still accessible if someone knows the direct URL.
* Limited Scope: Only hides the category from specific areas where you apply the CSS.
* Maintenance: If your theme updates, you might need to reapply the CSS rules.
When to use it:
* As a quick, temporary visual fix.
* When security is not a concern.
* For very simple hiding requirements (e.g., just hiding the category from a menu).
Choosing the Right Method
Here’s a quick guide to help you decide which method is best for you:
| Method | Difficulty | Security | Permanence | Use Case |
| ———————————- | ———- | ——– | ———- | ————————————————————————————————————————————— |
| Unpublishing Products | Easy | Low | Temporary | Small categories, temporary hiding. |
| Category Visibility Plugin | Easy | Medium | Medium | Most common scenarios, reliable and easy hiding. |
| Code Snippet | Medium | High | Permanent | Custom solutions, when you’re comfortable with code. |
| CSS | Easy | Very Low | Temporary | Simple visual hiding from specific areas, when security is not a concern. |
Important Considerations:
* SEO: Be mindful of how hiding categories might impact your SEO. Avoid creating broken links.
* User Experience: Ensure that hiding a category doesn’t create a confusing or frustrating experience for your customers.
* Backup: Always back up your website before making any significant changes, especially when working with code.
By using these methods, you can easily hide WooCommerce categories and tailor your store to meet your specific needs. Good luck!