普通网友 2019-06-10 14:27
浏览 114

如何使用PHP脚本和WooCommerce REST-API来更新我的订单

I am searching to run WooCommerce REST API with an Update. Its not a big issue to get data as json: https://www.example.com/wp-json/wc/v2/orders?consumer_key=ck_XXXXXXXXXXX&consumer_secret=cs_XXXXXXXXXXXX

But I am stuck at updating data and tried different approaches like:

<?php
$data = [
    'status' => 'completed'
];

print_r($woocommerce->put('orders/727', $data));
?>

or

$updated_order = $wc_api->update_order( 247, array( 'status' => 'completed' ) );

print_r( $updated_order );

But nothing happens...

This is my full php-code I am using:

<?php
require __DIR__ . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;

$woocommerce = new Client(
    'https://example.com',
    'consumer_key',
    'consumer_secret',
    [
        'wp_api' => true,
        'version' => 'wc/v3'
    ]
);
?>

//JSON response example:
echo($woocommerce->get(''));


$updated_order = $wc_api->update_order( 247, array( 'status' => 'completed' ) );

print_r( $updated_order );

// the updated order object will be returned 

?>

I assume there is a mistake I am addressing the API.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?