Update Order custom Field value with WooCommerce REST API



PHP Snippet 1:

$api_response = wp_remote_post('https://mujuonly.github.io/index.php/wp-json/wc/v3/orders/1631817799', array(
        'method' => 'PUT',
        'headers' => array(
            'Authorization' => 'Basic ' . base64_encode('ck_b0f7480d348807e3c065053e7810fb83ce3b6b41:cs_0c44e9ad9173fd3698010e86f1140914dcb8fc8a')
        ),
        'body' => array('billing' => array(
                'city' => 'Disssssmmmmss',
            ),
            'meta_data' => array(0 => array(
                    'key' => 'lworder',
                    'value' => 'orderd'
                )
            )
        )
    ));

    $body = json_decode($api_response['body']);

    if (wp_remote_retrieve_response_message($api_response) === 'OK') {
        echo 'The Order field  ' . $body->name . ' has been updated';
    }

PHP Snippet 2:

curl --location --request PUT 'https://yourwebsite.com/wp-json/wc/v3/orders/yourorderID' \
--header 'Authorization: Basic YOURTOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
"meta_data": [
    {
      "key": "testvalue",
      "value": 12
    }
  ]}'