使用 WooCommerce REST API 更新订单自定义字段值

Update Order custom Field value with WooCommerce REST API

我正在尝试更新订单自定义字段值 lworder。我使用了下面的代码,但没有找到任何更新。谁能帮我解决这个问题?

$api_response = wp_remote_post( 'https://your-website/wp-json/wc/v3/orders/{ORDER ID}', array(
    //'method'    => 'PUT',
    'headers' => array(
        'Authorization' => 'Basic ' . base64_encode( 'KEY:SECRET' )
    ),
    'meta_key' => array(
            'lworder' => 'ordered', 
    )
) );

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

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

使用 WooCommerce 6.1.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';
    }
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
    }
  ]}'