L
L
Larisa2019-01-10 15:48:48
WordPress
Larisa, 2019-01-10 15:48:48

How to write a condition for products in a specific Woocommerce category?

There is a task to display a certain block on the pages of a specific category of Woocommerce products and on the pages of all products belonging to this category.
There is is_product_category() to define a category, and for products you need something like in_product_category() similar to posts, but there is no such tag. How to write such a condition correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2019-01-10
@webkoshechka

$cats = array(91,22)
if ( has_term($cats, 'product_cat', $product_id ) ) {
    // выводим что нужно
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question