WooCommerce Rest API端点以将所有订阅绑定到特定客户

问题描述 投票:1回答:2

我不知道如何使用Woocommerce API获得特定的客户有效订阅。我有一个连接到中间层的移动应用程序,该中间层需要提供用户已激活的订阅列表。我需要知道可以调用哪些Woocommerce API端点或端点组合来获取用户的活动订阅。经过数天的努力来解决这个问题。请帮助

例如,使用WooCommerce API v1应该返回有效的订阅:https://....com/wp-json/wc/v1/subscriptions?customer=1&status=active但事实并非如此,很多用户都缺少有效的订阅。

我也尝试过:1。https://….com/wp-json/wc/v3/memberships/members尽管这确实会返回成员资格,但它不提供产品ID等,对于许多成员而言,它们都为null

“id”: 355,
“customer_id”: 1,
“plan_id”: 430,
“status”: “active”,
“order_id”: null,
“product_id”: null,
“subscription_id”: null,

2。https://….com/wp-json/wc/v3/orders?customer=1这也缺少订阅和其他购买

php woocommerce woocommerce-rest-api woocommerce-subscriptions wc-subscriptions
2个回答
0
投票

您可以通过以下方式获得有效的订阅:

/wp-json/wc/v1/subscriptions/<id> //To get particular subscription
/wp-json/wc/v1/subscriptions //To get all subscriptions

您可以在此处获取更多信息:https://prospress.github.io/subscriptions-rest-api-docs/?php#list-all-subscriptions

让我知道是否对您有帮助。


0
投票
/**
 * Register the routes for this class
 *
 * GET /customers/<id>/subscriptions
 *
 * @since 2.0
 * @param array $routes
 * @return array
 */
public function register_routes( $routes ) {
    # GET /customers/<id>/subscriptions
    $routes[ $this->base . '/(?P<id>\d+)/subscriptions' ] = array(
        array( array( $this, 'get_customer_subscriptions' ), WC_API_SERVER::READABLE ),
    );

    return $routes;
}

您的端点应该是 /customers/<id>/subscriptions-这里<id>customer_id

WCS API函数可将所有订阅绑定到特定客户。

© www.soinside.com 2019 - 2024. All rights reserved.