WooCommerce, wp cli and the mystery of the metavalues that won't change

56 views
Skip to first unread message

Tim Dobson

unread,
Oct 27, 2021, 8:15:32 PM10/27/21
to manchester-word...@googlegroups.com
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

Mike Little

unread,
Oct 28, 2021, 5:08:40 AM10/28/21
to Manchester WordPress WordPress User Group (MWUG)
Not got time to look this minute, but standard wp cli has additional commands for manipulating complex meta data.
See `post meta pluck` and `post meta patch` https://developer.wordpress.org/cli/commands/post/meta/

I'd hope woocommerce supported those too.
  

--
See the group blog at https://mwug.uk

You received this message because you are subscribed to the Google
Group "Manchester WordPress User Group".

To post to this group, send email to
manchester-word...@googlegroups.com

For more options, visit this group at
https://groups.google.com/group/manchester-wordpress-user-group
---
You received this message because you are subscribed to the Google Groups "Manchester WordPress User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manchester-wordpress-...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/manchester-wordpress-user-group/1b3a107c-b788-10be-4507-5b46bbb427bf%40tdobson.net.


--
Stay safe and healthy, best regards,

Mike



-- 
Mike Little
WordPress Specialist

Twitter: @mikelittlezed1

Founder and Director
Zed1.com Limited
https://zed1.com
Registered in England & Wales, no. 6745562
Zed1 Europe OÜ
Registered in Estonia, no. 14689554

Tim Dobson

unread,
Jan 5, 2023, 3:43:26 PM1/5/23
to Manchester WordPress User Group
Because I hate unanswered, incomplete things lying around... here's the answer:
Ultimately, I figured it out.

What's interesting though, is that I asked the question to ChatGPT... and got the correct answer right back. Sigh. The overlords have a future answering my inane queries!

Thanks for the encouragement Mike!

-Tim

Mike Little

unread,
Jan 5, 2023, 6:32:08 PM1/5/23
to Manchester WordPress WordPress User Group (MWUG)
Cool. Glad you got it figured out. 

I saw something today about ChatGPT consistently producing insecure code. I'd always treat ML output as "probably wrong".
Reply all
Reply to author
Forward
0 new messages