Hi @mediih,
Thank you for reaching out!
Can you share the request you are sending to add attribute terms so that we could try to exactly reproduce it on our end? Be sure not to include sensitive information that shouldn’t be made visible in a public forum.
Could you please also share a copy of your site’s System Status? You can find it via WooCommerce > Status. Select “Get system report” and then “Copy for support”. Once you’ve done that, paste it here in your response.
Cheers.
Thread Starter
mediih
(@mediih)
PUT
https://stock.spieziatyres.it/wp-json/wc/v3/products/%5Bid%5D
JSON
{
"attributes": [
{
"id": 11,
"position": 0,
"visible": true,
"variation": true,
"options": [
"option2"
]
}
]
}
Hi @mediih
There is no specific built-in API method to append an attribute to an existing product.
In order to accomplish that, you’d need first to retrieve the product’s data, programmatically append the additional attribute(s) to the existent object’s ‘attributes’ array, and then send the updated object via PUT.
I hope this provides clarity.
-
This reply was modified 4 years ago by
hegenberg.
Thread Starter
mediih
(@mediih)
@hegenberg can you help me to resolve the problem?
If I retrieve the product’s data I will have a list of existing attributes in JSON response.
If I use json path “$[0].attributes[0].options” the response will be:
[
“2B08”,
“2B10”
]
How can I append new attribute (2D5) to existing attributes in array? When I try to combine existing to new I have this error:
Only one attribute:
View post on imgur.com
Hi @mediih! Thanks for writing back!
As @hegenberg mentioned above, product-attributes are just like taxonomies, so you may need to retrieve the product data, using the get_post_meta() should work in this case!
Then, count the elements in that array to determine their positions, add the new attribute to the array and then update it.
If it’s not a default attribute, AFAIK, you can create a term.
Here’s a discussion about how to create a term if this is something that you’re looking for:
https://stackoverflow.com/a/29551092
In both cases, this is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone can chime in to help you out.
I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.
You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack.
We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.
All the best,
Hi there!
We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.
All the best!