首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Woocommerce: find_matching_product_variation归零

Woocommerce: find_matching_product_variation归零
EN

Stack Overflow用户
提问于 2020-10-20 00:13:04
回答 1查看 142关注 0票数 0

我有这段代码来根据选定的属性找到变量产品的变体id。

代码语言:javascript
复制
      $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

EN

回答 1

Stack Overflow用户

发布于 2020-10-20 18:05:36

我自己解决了,但也许有人需要解决同样的问题,我写下了对我有效的:

代码语言:javascript
复制
  foreach ($match_attributes] as $attribute) {
    $options['attribute_'.$attribute["slug"]] = $attribute["option"];
  }

我已经手动插入了"attribute_“前缀,现在一切都正常工作了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64431258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档