Woocommerce get new order id on subscription renewal

陌路散爱 提交于 2019-12-12 02:49:52

问题


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?

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

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

回答1:


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.

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

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

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 );
        }

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.

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



来源:https://stackoverflow.com/questions/32343242/woocommerce-get-new-order-id-on-subscription-renewal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!