如何在python中使用WooCommerceAPI向产品添加属性

2024-10-01 15:45:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我发现如何使用woocommerce rest api将属性传递给产品很困难

我成功地获取了属性id

我的职能:

def assign_attribute_to_products(wcapi_yachtcharterapp,post_id,attribute_id):
    #the post_id argument is the product id
    data = {
    "attributes": [
    {
      "id": attribute_id,
    },
  ],
    }
    wcapi_yachtcharterapp.put("products/"+str(post_id), data).json()

更新产品时不传递属性_id的信息

你知道怎么解决这个问题吗


Tags: therestapiiddata属性产品def
1条回答
网友
1楼 · 发布于 2024-10-01 15:45:17

您缺少一些数据,请查看here

这对我很有用:

data = {'attributes': [{'id': 7,
            'options': ['term01', 'term02'],
            'variation': 'true',
            'visible': 'true'}]}

即使可见变体的数据类型在文档中是布尔值,也必须使用字符串设置“真”或“假”。 对于变体,您必须包括选项

希望这有帮助

相关问题 更多 >

    热门问题