使用woocommerce API更改状态时出现PHP错误
我需要使用WooCommerceAPI通过将id和状态作为get参数传递来更改事务的状态。我不确定这是否是加载woo库的正确方法。我尝试了以下代码,但没有成功使用woocommerce API更改状态时出现PHP错误,php,wordpress,woocommerce,woocommerce-rest-api,Php,Wordpress,Woocommerce,Woocommerce Rest Api,我需要使用WooCommerceAPI通过将id和状态作为get参数传递来更改事务的状态。我不确定这是否是加载woo库的正确方法。我尝试了以下代码,但没有成功 <?php require __DIR__ . '/vendor/autoload.php'; use Automattic\WooCommerce\Client; $woocommerce = new Client( 'http://woosite.com', 'ck_XXXXXXXXXXXXXXXXXXXX
<?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"])
}
?>