Random News

How to hide a WooCommerce category from your shop page

For an e-commerce site, the most important page is the shop page where most of the business is done, and where customers can see the products for sale.

So the shop page has to be flawless; from presentation to functionality. By default, all the products from all categories will be shown which is fine for some, but not desirable for others.

You might only want to show a specific category on your shop page, but don’t know how. The following instructions created by our team will show you how to hide a WooCommerce category from your shop page.

  • First, you’ll need to find a slug for the category. Go to Products > Categories from the WordPress dashboard.
  • The slug for the Uncategorized category is “uncategorized”. If you want to make this category hidden from your child theme, enter the following code into functions.php.
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( 'uncategorised' ) ) ) { //pass the slug name here 
$new_terms[] = $term; }} 
$terms = $new_terms; } 
return $terms; }


the get_terms function has been added to the category. The category “Uncategorized” should not be visible anymore.

You can then enter the slug names for all the categories you want to hide separated by comma

Leave a comment

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