0

I want to check product tag at single product page.

For example, when user access single product page

if that product tag is "adult"

redirect to main page.

I found is_product_tag() but this function only work at archive page.

Is there a way to know the tags on a single product page?

0

To check if the product has the tag, you can use has_term() or is_object_in_term().

has_term( 'tag_slug_or_ID', 'product_tag' )

Or:

// checking if the product has any tag
is_object_in_term( $product_id, 'product_tag' )
// checking if the product has a given tag
is_object_in_term( $product_id, 'product_tag', 'tag_slug_or_ID' )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.