我有这段代码来根据选定的属性找到变量产品的变体id。
$match_attributes = array(
'pa_color' => 'grey',
'pa_base' => 'circular',
'pa_text' => 'no',
'pa_font' => 'kaushan-script'
);
$data_store = WC_Data_Store::load( 'product' );
$variation_id = $data_store->find_matching_product_variation(
new \WC_Product( $myProductId), $match_attributes
);$match_attributes是正确的,但仍然收到零$variation_id = 0,有什么问题吗?还有另一种方法可以获得变体id吗?
Tnx
发布于 2020-10-20 18:05:36
我自己解决了,但也许有人需要解决同样的问题,我写下了对我有效的:
foreach ($match_attributes] as $attribute) {
$options['attribute_'.$attribute["slug"]] = $attribute["option"];
}我已经手动插入了"attribute_“前缀,现在一切都正常工作了。
https://stackoverflow.com/questions/64431258
复制相似问题