Woocommerce 在订阅续订时获得新的订单 ID [英] Woocommerce get new order id on subscription renewal

查看:31
本文介绍了Woocommerce 在订阅续订时获得新的订单 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我订阅了 Woocommerce,并且设置了 Stripe 网关并正常工作.每次我手动测试预定的续订时,它都会为续订保存一个新的订单 ID,但是我找不到访问它的方法.我将 scheduled_subscription_payment() 设置为打印我们的 $order 对象,但由于订阅引用初始订单,order_id 始终相同.有没有办法在订阅续订触发后立即获取新订单 ID?

I have Woocommerce subscriptions with the Stripe Gateway setup and working. Each time I manually test a scheduled renewal it saves a new order id for the renewal however I can't find a way to access this. I have the scheduled_subscription_payment() set to print our the $order object but the order_id is always the same due to the subscription referencing the initial order. Is there a way to get the new order id for a subscription renewal right after it is triggered?

我引用的功能在 Stripe WC Gateway 插件中:

The function I'm referencing is in the Stripe WC Gateway plugin:

public function scheduled_subscription_payment( $amount_to_charge, $order, $product_id )

推荐答案

似乎在 WooCommerce Subscriptions 的最新版本 (2.0.0) 中,他们弃用了旧的 schedule_subscription_payment 挂钩,并替换为新的 woocommerce_scheduled_subscription_payment 挂钩.

It seems that in the last release (2.0.0) of WooCommerce Subscriptions they deprecated the old scheduled_subscription_payment hook, and replaced with the new woocommerce_scheduled_subscription_payment hook.

旧参数是:$amount、$original_order、$product_id.

Old arguments were: $amount, $original_order, $product_id.

虽然新的是:$amount、$renewal_order.

While the new ones are: $amount, $renewal_order.

因此,使用最新版本的 WC 订阅,您可以直接访问新的续订订单数据.要从续订中检索父订单,您可以使用:

So, using the last version of WC Subscriptions you can directly access the new renewal order data. To retrieve the parent order from the renewal, you can use:

        if ( wcs_order_contains_renewal( $renewal_order->id ) ) {
            $parent_order_id = WC_Subscriptions_Renewal_Order::get_parent_order_id( $renewal_order->id );
        }

如果你不能拿到最后一个WC Subscriptions插件,那么从父级获取续订订单是很棘手的:你可能可以从给定的父级订单中获取所有续订订单并取最后一个,但你不是100% 确定这是正确的顺序.

If you can't get the last WC Subscriptions plugin, it is tricky to get the renewal order from the parent: you can probably get all the renewal orders from the given parent order and take the last one, but you are not 100% sure this is the right order.

无论如何,如果你能拿到最后一个 WC Subscriptions 版本肯定是一个更好的主意.

Anyway, if you can get the last WC Subscriptions version is surely a better idea.

这篇关于Woocommerce 在订阅续订时获得新的订单 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆