Vpa*_*ant 2 php wordpress product custom-taxonomy woocommerce
我想确定产品是否具有属性。例如:
if (product has attribute 'pa_color')
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
您可以通过以下方式简单地使用该WC_Product方法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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2819 次 |
| 最近记录: |