PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 5, 2022

[FIXED] Update Order custom Field value with WooCommerce REST API

 February 05, 2022     json, php, woocommerce, woocommerce-rest-api, wordpress     No comments   

Issue

I am trying to update the Order custom field value lworder. I used the below code but I did not find any update. Can anyone please help me with this?

$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';
}

Solution

Tested OK with 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';
    }


Answered By - mujuonly
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing