Sub*_*air 2 wordpress product variations woocommerce
我如何从自定义产品循环中获取产品版本ID。我有变异属性,例如
{ 'pa_color'=>'red','pa_size'=>'large'}
Run Code Online (Sandbox Code Playgroud)
匹配的属性集是
[
'attribute_pa_color' => 'blue',
'attribute_pa_size' => 'small',
];
Run Code Online (Sandbox Code Playgroud)
下面是我最终创建的用于实现此功能的功能:
/**
* Find matching product variation
*
* @param $product_id
* @param $attributes
* @return int
*/
function find_matching_product_variation_id($product_id, $attributes)
{
return (new \WC_Product_Data_Store_CPT())->find_matching_product_variation(
new \WC_Product($product_id),
$attributes
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2138 次 |
| 最近记录: |