如何解决Woocommerce:find_matching_product_variation返回零
我有这段代码可以根据所选属性找到变量产品的版本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
解决方法
我自己解决了,但也许有人需要解决相同的问题,我写下对我有用的内容:
foreach ($match_attributes] as $attribute) {
$options['attribute_'.$attribute["slug"]] = $attribute["option"];
}
我已经手动插入了“ attribute_”前缀,现在一切都按预期工作了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。