通过API取消WooCommerce订阅

时间:2019-04-16 20:11:37

标签: woocommerce woocommerce-subscriptions

我正在使用WooCommerce订阅API https://prospress.github.io/subscriptions-rest-api-docs/#update-a-subscription将用户订阅的状态从有效更新为“待取消”。一切正常,用户状态更改为站点。但是当到期日期到来时,Woocommerce不会将订阅变成“已取消”。

这是我的代码

$woocommerce = new Client(
            'https://example.com', 'ck_xxxxxxxxxxxxxxxxxx', 'cs_xxxxxxxxxxxxxxxxxxxxx', [
        'wp_api' => true,
        'version' => 'wc/v1',
            ]
    );

    try {
        $subscription = $woocommerce->get('subscriptions/' . $subscription_id);
        $next_payment_date = $subscription->next_payment_date;
        $end_date = date("Y-m-d H:i:s", strtotime("+2 hour", strtotime($next_payment_date)));

        $data = [
            'status' => 'pending-cancel',
            'end_date' => $end_date
        ];

        $woocommerce->put("subscriptions/$subscription_id", $data);
    } catch (HttpClientException $e) {
        $msg = $e->getMessage() . ' ' . $e->getRequest() . ' ' . $e->getResponse();
        echo $msg;
    }

0 个答案:

没有答案
相关问题