我如何从自定义产品循环中获取产品变体 ID。
我有变化属性,比如,
{ 'pa_color'=>'red','pa_size'=>'large'}
最佳答案
要匹配的属性集是
[
'attribute_pa_color' => 'blue',
'attribute_pa_size' => 'small',
];
下面是我最终创建的函数来实现这一点:
/**
* 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
);
}
关于wordpress - WooCommerce:从匹配的属性中获取产品变体 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53958871/