How to check if I am displaying categories on a Woocommerce page? [closed]

I am using the Woocommerce plugin. I am trying to create a different container for when I am displaying multiple products then when I display multiple categories.

So far in my archive_products I have a check for is_shop() and if it is then it means that I am displaying categories and not products. So I load my category style containers.

The problem is that if the category has sub categories and you click to see those sub categories, you are now failing the is_shop() function.

How can I still know if I am up to displaying available products or if I am displaying subcategores?

1 Answer
1

I think the conditional you’re looking for is:

is_product_category()
Returns true when viewing a product category archive.

You can see the docs at Conditional Tags

A bit of Google searching seems to indicate that this isn’t always reliable, depending upon your scenario. See here on WordPress codex.

Leave a Comment