Replies: 2 comments 3 replies
-
Thanks for your post. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Thanks for helping me on this. That's the same code that I had but using my array that I'm sending when I PUT is:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I created my own custom brand (product_brands) as a taxonomy and added it to the REST API using this code:
I can see brands attached when I use a GET for products, and with only this code I could not PUT OR POST a product with this brand.
So I added this code:
This works if I PUT an array to the body of an existing product endpoint to allow me to add brand terms. My array is just
product_brands[61]
(which is the ID of one of my existing brand terms.) I found that I can use an ID if I usewp_set_post_terms
(notwp_set_object_terms
).set_object_terms
will only allow me to use the brand slug.However, neither option works if I try to POST a NEW product with an existing brand term. Nothing gets set into the brand for the product.
I've looked high and low for documentation on this but came up short. Here's some further notes/assumptions and questions.
Some sites said to use
woocommerce_rest_pre_insert_product
and some saidwoocommerce_rest_pre_insert_product_object
. My understanding is that usingobject
is the new way to do it.I didn't get some of the parameters either. Sometimes it was
$object
and sometimes it was$product
. Either case seems to work but I think it may have to do with whether I used the filterwoocommerce_rest_pre_insert_product_object
orwoocommerce_rest_pre_insert_post_object
. I'm not sure.Beta Was this translation helpful? Give feedback.
All reactions