admin管理员组

文章数量:1279112

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?

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?

Share Improve this question asked Jul 23, 2019 at 16:50 Kt HKt H 152 silver badges6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

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' )

本文标签: How to check woocommerce single product tag