Woocommerce:查找匹配的产品变量返回零
我使用此代码根据所选属性查找变量产品的变体idWoocommerce:查找匹配的产品变量返回零,woocommerce,woocommerce-rest-api,Woocommerce,Woocommerce Rest Api,我使用此代码根据所选属性查找变量产品的变体id $match_attributes = array( 'pa_color' => 'grey', 'pa_base' => 'circular', 'pa_text' => 'no', 'pa_font' => 'kaushan-script' ); $data_store = WC_Data_Store::load(
$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_属性是正确的,但仍然接收零$variation_id=0,有什么问题吗?还有其他方法可以获取变体id吗
Tnx由我自己解决,但也许有人需要解决同样的问题,我写下对我有用的东西:
foreach ($match_attributes] as $attribute) {
$options['attribute_'.$attribute["slug"]] = $attribute["option"];
}
我已经手动插入了“attribute_u2;”前缀,现在一切正常