Auto complete orders when a renewal successful payment is made on a subscription in WooCommerce
·
Answer a question
I am using WooCommerce Subscriptions plugin for subscriptions and it is recurring the order on subscription renewal and what I need is that when the order recurring order is created after successful subscription renewal payment the order status should changed to completed.
I have tried to use unsuccessfully the following hooks:
woocommerce_renewal_order_payment_complete
woocommerce_order_status_changed
woocommerce_payment_complete
Answers
For WooCommerce Subscriptions you need to use woocommerce_subscription_payment_complete
action hook, that is triggered when a renewal payment is made on a subscription.
You can try the following that will update the current order status to completed:
add_action('woocommerce_subscription_payment_complete', 'subscription_payment_complete_hook_callback', 10, 1);
function subscription_payment_complete_hook_callback( $subscription ) {
// Get the current order
$current_order = $subscription->get_last_order( 'all', 'any' );
// For Paypal recurring orders
if( $current_order->get_payment_method() === 'paypal' ) {
// Update status to completed
$current_order->update_status('completed');
}
}
Related documentation: WooCommerce Subscriptions action hooks
更多推荐
所有评论(0)