简体   繁体   English

woocommerce:产品属性不会增值

[英]woocommerce: product attribute will not add value

I'm programmatically creating attribute variations (variable product).我正在以编程方式创建属性变体(可变产品)。 Everything I've seen does this easily, but the value simply does not show up.我所看到的一切都很容易做到这一点,但价值根本没有出现。 Here's my code:这是我的代码:

$thedata = Array(
     'pa_performance_dates' =>  Array( 
          'name'        => 'pa_performance_dates', 
           'value'      =>  $arrayOfTermIDs,
           'position'   => 1,
           'is_visible' => '1',
           'is_variation' => '1',
           'is_taxonomy' => '1'
      )
);
update_post_meta( $product_id, '_product_attributes', $thedata );

Attribute: "Performance Dates" WORKING属性:“演出日期”工作
Attribute Values (terms under attribute): "1571986800" WORKING属性值(属性下的术语):“1571986800”工作
Attribute Values being added under the Product ID: NOT WORKING在产品 ID 下添加的属性值:不工作

属性值仍然为空

I have tried everything: setting the VALUE above to an array of the terms slugs, an array of the IDs, a simple string of an ID or slug/value.我已经尝试了所有方法:将上面的 VALUE 设置为术语 slugs 的数组、ID 的数组、ID 或 slug/值的简单字符串。 Nothing works.没有任何效果。 I've also followed these stackoverflow questions:我也关注了这些 stackoverflow 问题:
woocommerce: add value to a product attribute woocommerce:为产品属性添加价值
Creating WooCommerce product variation adds an empty attribute value 创建 WooCommerce 产品变体会添加一个空属性值
Add Product Attributes with values to a product in Woocommerce 为 Woocommerce 中的产品添加带有值的产品属性

I've also tested the product_id variable and that is correctly showing the ID of the post.我还测试了 product_id 变量,它正确显示了帖子的 ID。

What am I doing wrong?????!?我究竟做错了什么?????!?

To add value to an attribute of a product use wp_set_object_terms要为产品的属性添加价值,请使用wp_set_object_terms

For example: $arrayOfTermIDs = array( 'Test1', 'Test2', 'Test3' );例如: $arrayOfTermIDs = array( 'Test1', 'Test2', 'Test3' );

foreach ($arrayOfTermIDs as $arrayOfTermID) {
    $term_taxonomy_ids = wp_set_object_terms( $product_id, $arrayOfTermID, 'pa_performance_dates', true );          
}

To append the value set the last argument as true or set it to false to overwrite.对于 append 值,将最后一个参数设置为true或将其设置为false以覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM