My aim is to give value to a custom created product attribute with the usage of woocommerce API.
But I do not know how to do it. The official API documentation does not
mention anything about that.
I used to do the create like this:
product_attributes = {
"attributes": [
{
"name" : "color",
"slug":"color_slug",
"visible": True,
"options": [
"blue",
"black",
]
}
]
}
wcapi_yachtcharterapp.post("products/attributes", product_attributes).json()
and the update like this:
product_attributes = {
"attributes": [
{
"name" : "color",
"slug":"color_slug",
"visible": True,
"options": [
"blue",
"black",
]
}
]
}
wcapi_yachtcharterapp.put("products/attributes/"+str(post_id), product_attributes).json()
but nothing works.
I assume that I have to create first the attribute and then give a value.
2
Answers
You need to add the attribute first and then the attribute terms.You have to do it in different endpoints. This is how I do it :
ID used in attribute terms endpoint is the attribute id.
Hope this helps!