Using wp wc CLI to add meta_data
-
I feel like I should be able to do
sudo wp wc customer update 141 --meta_data="[{"key":"test_meta1","value":"test_meta_value"}]" --user=1However, this does not work.
The result I get is
Success: Updated customer 141.However,
sudo wp wc customer get 141 --fields=meta_data --user=1 | grep test_metareturns blank.
curl -X PUT https://www.example.com/wp-json/wc/v3/customers/141 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{"meta_data": [{"key": "test_meta1","value": "test_meta_value"}]}'would work, but I’d prefer to use the wp wc CLI if possible, rather than the REST API.
I’ve also tried adding meta_data to products, with similar challenges – eg
sudo wp wc product create --name="test2" --sku="test2" --regular_price=10 --meta_data="[{"meta_data": [{"key": "test_meta1","value": "test_meta_value"}]}]" --user=1What’s the right format for supplying meta_data on the wp wc CLI command line interface? I get it needs to be an array… but what format does that actually mean? Can anyone product a working example?
-
This topic was modified 3 years, 8 months ago by
tdobson.
-
This topic was modified 3 years, 8 months ago by
-
Golly. This is a new record. I’ve fixed it.
I spent FOUR MONTHS on this problem, registered for this forum specially…
..and solved it myself within 5 mins of registering.
The syntax is:
--meta_data='[{"key": "test_meta1","value": "test_meta_value"}]'eg
sudo wp wc product create --name="test4" --regular_price=10 --meta_data='[{"key": "test_meta1","value": "test_meta_value"}]' --user=1I better go and close my own stackoverflow question.
Hi @tdobson
It is great that you resolved it already! Thanks for sharing your solution with the WooCommerce community.
I’d like to keep you informed that in future if needed you can get better coding-related help at the following development related channels, as support for custom coding is beyond the scope of support we are able to provide in this forum. This particular forum is for questions that are related to the WooCommerce core features.
- WooCommerce Developer Resources Portal: https://developer.woocommerce.com/
- WooCommerce Slack Community: https://woocommerce.com/community-slack/
- WooCommerce Community on Facebook: https://www.facebook.com/groups/advanced.woocommerce/
Thanks
The topic ‘Using wp wc CLI to add meta_data’ is closed to new replies.