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 )
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.