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 badges1 Answer
Reset to default 2To 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
版权声明:本文标题:How to check woocommerce single product tag 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741277813a2369832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论