php - 使用 woocommerce API 更改状态时出现 PHP 错误
问题描述
我需要通过将 id 和 status 作为 get 参数传递来使用 woocommerce API 更改交易的状态。我不确定这是否是加载 woo 库的正确方法。我尝试了以下代码但徒劳无功
<?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"])
}
?>
解决方案
推荐阅读
- wordpress - 无法使用 2 个 wordpress 实例连接到我的数据库 - swarm 已禁用?
- javascript - 如何将 ajax $.get 值传递给 jQuery 中的另一个 $.get 函数?
- javascript - 通过 Ajax 提交表单后,提交按钮被冻结
- android - 如何在 Kotlin(Android)中等待 firebase 调用结束
- gradle - 这个“all*.exclude”在 Gradle 传递依赖中是什么意思?
- javascript - 如何在表格中使用逗号作为千位分隔符,javascript
- javascript - 如何从firebase中删除数据?
- linux - 替换 2 个匹配词之间的所有行
- vba - 按日期从文件夹中打开 3 个文件
- r - 如何计算正态分布大于或等于 R 中某个值的概率?