通过WooCommerce中的自定义分类法定位产品字词 [英] Targeting product terms from a custom taxonomy in WooCommerce
问题描述
我在网站上使用了一些自定义分类法... movies_type
(其中之一)并有4个术语:
I use some custom taxonomies in my website… movies_type
(is one of them) and has 4 terms:
-
电影
, -
tvseries
, -
concert-和仪式,
-
纪录片
movie
,tvseries
,concert-and-ceremony,
documentary
我已经用以下任一术语标记了每个产品。
I have tagged Every product with just one of this terms.
我该如何定位那些具有相同期限的产品?
How can I target those products that have the same term?
谢谢
推荐答案
您可以使用 has_term() WordPress函数进行定位您的产品,其术语来自定制分类法,就像产品类别一样,定制分类法是 product_cat
You can use has_term() WordPress function to target your products with terms from a custom taxonomy, just as for product categories which custom taxonomy is "product_cat"
例如,您可以通过以下方式使用它:
For example, you can use it this way:
if ( has_term( 'movie', 'movies_type' ) ) {
// Do something
} elseif ( has_term( 'tvseries', 'movies_type' ) ) {
// Do another thing
}
这应该适合您……
对于产品类别,您将使用'product_cat'
自定义分类法:
For product categories you will use 'product_cat'
custom taxonomy:
if ( has_term( 'clothing', `'product_cat'` ) ) {
// Do something
}
对于产品标签,您将使用'product_tag'
自定义分类法:
For Product tags you will use 'product_tag'
custom taxonomy:
if ( has_term( 'books', 'product_tag' ) ) {
// Do something
}
这篇关于通过WooCommerce中的自定义分类法定位产品字词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!