Hello Friends and MWUG enthusiasts,
I have a Woocommerce order I'm trying to manipulate using the WP
WooCommerce CLI.
Specifically, I'm trying to update the value of one of the meta values.
Here's what we have to start with.
bitnami@ip-172-26-15-175:~$ sudo wp wc shop_order get 3042
--field="meta_data" --user=1
[{"id":50083,"key":"is_vat_exempt","value":"no"},{"id":50084,"key":"automatewoo_cart_id","value":"513"},{"id":50091,"key":"_new_order_email_sent","value":"true"},{"id":50093,"key":"_ga_tracked","value":"1"},{"id":50094,"key":"_automatewoo_order_created","value":"1"},{"id":50095,"key":"cc_attendance","value":"pending"},{"id":50096,"key":"cc_volunteer","value":"rounding_up"},{"id":50097,"key":"email_confirmation_pre_event","value":"sent"},{"id":50098,"key":"_aw_is_paid","value":"1"},{"id":50492,"key":"email_wednesday_volunteer_rounding_up","value":"sent"},{"id":50493,"key":"cc_volunteer_attendance","value":"pending"}]
Here's one idea about what a command to do that would look like, and wp
cli accepts it, which is nice:
bitnami@ip-172-26-15-175:~$ sudo wp wc shop_order update 3042
--meta_data='{"50493":"cc_volunteer_attendance":"noaction"}' --user=1
Success: Updated shop_order 3042.
However, if we look, we have updated absolutely at all.
bitnami@ip-172-26-15-175:~$ sudo wp wc shop_order get 3042
--field="meta_data" --user=1
[{"id":50083,"key":"is_vat_exempt","value":"no"},{"id":50084,"key":"automatewoo_cart_id","value":"513"},{"id":50091,"key":"_new_order_email_sent","value":"true"},{"id":50093,"key":"_ga_tracked","value":"1"},{"id":50094,"key":"_automatewoo_order_created","value":"1"},{"id":50095,"key":"cc_attendance","value":"pending"},{"id":50096,"key":"cc_volunteer","value":"rounding_up"},{"id":50097,"key":"email_confirmation_pre_event","value":"sent"},{"id":50098,"key":"_aw_is_paid","value":"1"},{"id":50492,"key":"email_wednesday_volunteer_rounding_up","value":"sent"},{"id":50493,"key":"cc_volunteer_attendance","value":"pending"}]
So what am I missing?
The documentation is fairly unhelpful in terms of examples from what I
see:
https://github.com/woocommerce/woocommerce/wiki/WC-CLI-Overview
I'd prefer to the CLI to do this (currently I'm hitting the database
values just fine
UPDATE wp_postmeta as t, (SELECT order_id FROM
wp_order_product_customer_lookup where order_id=$id) as temp SET
meta_value='noaction' WHERE temp.order_id = t.post_id AND
meta_key='cc_volunteer_attendance'
but I'd prefer a nice common, safe interface).
The meta value handling in woocommerce seems much harder to get my head
around than in WordPress proper - eg to update a user's metavalue:
sudo wp user meta update $id $meta_key $meta_value --user=1
Does anyone have any bright thoughts about how I format this in a way
that might work?
Cheers,
-Tim