我想确定产品是否具有属性。例如:
if (product has attribute 'pa_color')
{
//do something
}
我怎样才能做到这一点?
您只需使用WC_Product
method get_attribute()
这边走:
// (If needed) Get an instance of the WC_Product Object from the product ID
$product = wc_get_product( $product_id );
// Get the product attribute value(s)
$color = $product->get_attribute('pa_color');
// if product has attribute 'pa_color' value(s)
if( ! empty( $color ) ){
// do something
} else {
// No product attribute is set for this product
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)