WooCommerce REST API:更新产品变体属性将属性名称和选项设置为 Any:Any

WooCommerce REST API: updating product variation attributes sets attribute name and option to Any:Any

所以,我正在使用端点 https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation 更新变体的现有属性。这些属性在用于变体之前已添加到产品中。但是,将现有属性更新为可用值就是将它们设置为 Any:Any(这意味着属性已被空数组覆盖)并且现在可以在网上商店以任意组合的属性购买产品。

例如- 产品变体的现有属性是:

[{"name":"Brand", "options": "Bare Denim"},{"name":"Material", "options": "Cotton"}]

并将属性更新为 BrandMaterial:

中的可用选项之一
[{"name":"Brand", "options": "Levis"},{"name":"Material", "options": "Polyester"}]

正在将变体属性设置为空数组。更新后的变体属性:

[]

这是更新产品变体属性的正确方法吗?属性可以通过这种方式更新还是必须在这种情况下创建新的变体?

经过数小时的调试和寻找解决此问题的方法后,我发现这是我的一个愚蠢的错误,它是给 选项 提供变体属性而不是 选项。基本上,虽然使用 creating/updating 产品属性 nameoptions 并且在 creating/updating 变体属性 name 选项要通过。

对于所有面临创建或更新产品变体属性问题的人,请检查一下这两个键是否正确传递。主要问题只会在这里解决。

回答我上面的问题:

Is this the right way of updating product variation attributes?

这是正确的方法,但需要更正。更正变体属性的请求数据(注意它是 option 而不是 options):

[{"name":"Brand", "option": "Levis"},{"name":"Material", "option": "Polyester"}]

Can the attributes be updated this way or will have to create a new variation in this case?

可以使用此更新现有的变体属性,如果需要,我们可以创建新的。

参考文献: