gpt4 book ai didi

api - woocommerce api 创建具有变体的新产品

转载 作者:行者123 更新时间:2023-12-01 18:54:31 29 4
gpt4 key购买 nike

我想使用 woocommerce api 创建新产品。我有一个颜色属性,我想识别 sku 中的产品,例如 codeblack。

我的问题是如何做到这一点。

在创建带有倾斜、描述、sku 等的产品时,这是可以的。为了创建具有属性的产品,我添加了 'type' => 'variable'

现在我有了属性,我启用了变体,但我无法为我的变体赋予值(value)。

这是我的代码

    $client->products->create( 
array(
'title' => 'Premium Quality',
'type' => 'variable',
'sku' => 'code',
'regular_price' => '29.98',
'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
'images' => array(
array(
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
'position' => 0

),
array(
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
'position' => 1
)
),
'attributes' => array(
array(
'name'=>'color',
'slug'=>'color',
'position'=>'0',
'visible'=>'true',
'variation'=>'true',
'options'=>array('red','black')
)
),
'variations' => array(
array(
'sku' => 'codered',
'regular_price' => '29.98',
'attributes' => array(
array(
'name'=>'color',
'options'=>'red'
)

)
),
array(
'sku' => 'codeblack',
'regular_price' => '29.98',
'attributes' => array(
array(
'name'=>'color',
'options'=>'black'
)
)
)
)

)

);

所以我有我的属性 enter image description here

但我无法将它们与变体匹配 enter image description here

最佳答案

您可以使用变体/批处理并使用您现有的产品属性,它对我有用...... enter image description here

关于api - woocommerce api 创建具有变体的新产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37823867/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com