通过 API 删除 WooCommerce 商店中不再存在的项目的订阅订单项

发布于 2025-01-09 17:20:26 字数 1342 浏览 6 评论 0原文

背景

我有大约 1000 个订阅,需要运行并删除订单项。 Woocommerce 以某种方式允许我们删除与订阅相关的产品,这意味着现在有多达 1000 个订阅中的产品不再存在。

这给订阅者带来了许多问题,例如无法手动续订,因为他们会收到不存在的产品错误。 我可以手动删除它们,点击进入订阅并按每个订阅 1 1 删除 10 多个项目。手动执行此操作将花费太长时间。

我想要做什么:

我想一一遍历所有订阅,查看订单项,并删除“parent_id”为 0 的所有订单项。

什么到目前为止我已经尝试过了:

我已经尝试了下面的 JSON 的许多变体(也包括带和不带“订阅”行的),这就是我目前所处的位置。

在此处查看 API 信息

在此处查看订单项信息

注意:我没有收到任何错误消息,请求响应为 200。但没有任何项目被删除...

curl -X PUT https://example.com/wp-json/wc/v3/subscriptions/{subscriptions_id} \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
       "subscription":{
          "line_items":[
             {
                "product_id":0,
                 "quantity":0
             }
          ]
       }
    }'

我需要帮助:

至少知道我是否走在正确的道路上,或者我想做的事情是否可能。但理想情况下,为我指明正确的方向,或者帮助修复我的 API 请求。

提前致谢!!

注2: 我无法为此使用 AutomateWoo,因为 AutomateWoo 要求产品存在,然后您才能选择/删除它。

Background:

I have about 1000 subscriptions that I need to run through and delete line items. Woocommerce has somehow allowed us to delete products that are tied to subscriptions, meaning there are now up to 1000 subscriptions with products in them which no longer exist.

This creates many problems for the subscribers, such as not being able to manually renew, as they get errors for the products that do not exist.
I can delete them manually, where I will click into a subscription and remove 10+ items 1 by 1 per subscription. This will take way too long manually.

What I’m trying to do:

I want to run through all the subscriptions 1 by 1, look through the line items, and remove any line items where the “parent_id” is 0.

What I have tried so far:

I’ve tried many variations of the JSON below (also both with and without the 'subscription' line), and this is where I am at currently.

See API info here

See line item info here

NOTE: I get no error messages, the request reponse is 200. But no items are removed...

curl -X PUT https://example.com/wp-json/wc/v3/subscriptions/{subscriptions_id} \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
       "subscription":{
          "line_items":[
             {
                "product_id":0,
                 "quantity":0
             }
          ]
       }
    }'

What I would like help with:

At the very least to know if I'm on the right track, or if what I'm trying to do is even possible. But ideally, to point me in the right direction, or help fix up my API request.

Thanks in advance!!

NOTE 2:
I can't use AutomateWoo for this, as AutomateWoo requires the product to exist before you can select it / remove it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除会话 2025-01-16 17:20:26

弄清楚了...

所以如果您想删除它,您需要使用“id”而不是“product_id”来引用该行项目。因为“id”永远不会为空(即使产品不存在),我必须使用不同的 API 端点构建复杂的自动化。

您需要

  1. 列出所有
  2. 自动运行每个订阅的订单项的订阅,只允许product_id = 0 的订阅通过运行
  3. 正确的 JSON 来删除引用“id”的订单项

{

"line_items": [{
    "id": 18756,
    "quantity": 0
}]

}

Figured it out...

So you need to refer to the line item by using 'id' and not 'product_id' if you want to remove it. Because the 'id' is never empty (even if the product doesn't exist), I had to build a complex automation using different API endpoints.

You need to

  1. list all subscriptions
  2. have automation run through line items per subscription, only allowing ones with product_id = 0 to pass
  3. run the proper JSON to delete the line items referencing the 'id'

{

"line_items": [{
    "id": 18756,
    "quantity": 0
}]

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文