WooCommerce Rest API 端点,用于获取与特定客户相关的所有订阅

我不知道如何使用 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 等,其中许多产品 ID 为空会员资格


“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 这也缺少订阅和其他购买


qq_笑_17
浏览 197回答 3
3回答

MMMHUHU

/**&nbsp;* Register the routes for this class&nbsp;*&nbsp;* GET /customers/<id>/subscriptions&nbsp;*&nbsp;* @since 2.0&nbsp;* @param array $routes&nbsp;* @return array&nbsp;*/public function register_routes( $routes ) {&nbsp; &nbsp; # GET /customers/<id>/subscriptions&nbsp; &nbsp; $routes[ $this->base . '/(?P<id>\d+)/subscriptions' ] = array(&nbsp; &nbsp; &nbsp; &nbsp; array( array( $this, 'get_customer_subscriptions' ), WC_API_SERVER::READABLE ),&nbsp; &nbsp; );&nbsp; &nbsp; return $routes;}你的端点应该是 /customers/<id>/subscriptions- 这里<id>是customer_idWCS API 函数获取与特定客户相关联的所有订阅。

不负相思意

您可能不再寻找这个,但我想我会澄清答案,因为 @mujuonly 不方便地遗漏了它仅适用于Legacy WooCommerce API.&nbsp;无论如何,它已被弃用。但它现在有效。在 WooCommerce -> 设置 -> 高级 -> 旧版 API 中启用旧版 API获取您的访问令牌访问https://___.com/wc-api/v3/customers/<customer_id>/subscriptions/截至目前,我没有看到本机 API 支持类似此端点的任何内容。希望它会在不久的将来被添加。

互换的青春

您可以使用以下方式获得有效订阅:/wp-json/wc/v1/subscriptions/<id>&nbsp;//To&nbsp;get&nbsp;particular&nbsp;subscription /wp-json/wc/v1/subscriptions&nbsp;//To&nbsp;get&nbsp;all&nbsp;subscriptions您可以在此处获取更多信息:&nbsp;https ://prospress.github.io/subscriptions-rest-api-docs/?php#list-all-subscriptions如果您觉得有帮助,请告诉我。
打开App,查看更多内容
随时随地看视频慕课网APP