• Resolved tdobson

    (@tdobson)


    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=1

    However, 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_meta

    returns 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=1

    What’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 2 years, 6 months ago by tdobson.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tdobson

    (@tdobson)

    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=1

    I 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.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using wp wc CLI to add meta_data’ is closed to new replies.