PHP error while changing the status using woocommerce API

49 Views Asked by At

I need to change the status of the transation using the woocommerce API by passing the id and status as get parameters. I am not sure whether this is the right way to load a woo library. I have attempted the following code but in vain

<?php

require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;

$woocommerce = new Client(
    'http://woosite.com', 
    'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 
    'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    [
        'version' => 'wc/v3',
    ]
);
$json = '{"1": "pending","2": "processing","3": "on-hold","4": "completed","5": "cancelled","6": "refunded","7": "failed"}'

$actionObj = json_decode($json)

$id = $_GET['id'];
$action = $_GET['action'];

    if (isset($id) && isset($action)) {
        $data = [
            'status' => $actionObj[$id]
        ];

        $response  = $woocommerce->put('orders/'. $id , $data);
        print_r("You have changed the status of the order " . $id . " as " + $response["status"])
    }

?>
0

There are 0 best solutions below