Check If Current Page is a Product Category

Are you using is_category() and nothing works?… This tutorial is just for you then.

Please keep in mind, that product categories in WooCommerce are just a WordPress taxonomy product_cat. It means that it is possible to use all the conditional tags related to taxonomies as well.

But let’s begin with WooCommerce conditional tags first.

Examples:

if( is_product_category() ) {
	// yay, we are on a product category page!
} else {
	
}

It is also possible to pass multiple values as an array:

if( is_product_category( array( 5, 10, 891 ) ) ) {
	// do something for product categories with ID = 5 or 10 or 891
} elseif( is_product_category( 'snowboards' ) ) {
	// do something only for product categories with slug or title "snowboards"
} else {
	// do something else for other pages
}

Do you remember I mentioned before that product categories are taxonomies? So, here is the list of WordPress native conditional tags we can use as well:

This is the example, similar to above:

if( is_tax( 'product_cat', array( 5, 10, 891 ) ) ) {
	
} elseif( is_tax( 'product_cat', 'snowboards' ) ) {
	
} else {
	
}

The reasonable question is – “What is the difference?”

There is no difference, the function is_product_category() is just a wrapper for is_tax( 'product_cat' ).

Well, maybe the only thing you should keep in mind is if you decide to deactivate WooCommerce plugin without changing a theme, all your is_product_category() functions will return error 500 unless you add an additional condition function_exists( 'is_product_category' ).

I have another tutorial in case you’re looking for how to check if products is in category.

Misha Rudrastyh

Misha Rudrastyh

Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.

Need some developer help? Contact me

Follow me on Twitter