Search code examples
hook-woocommercewoocommerce-subscriptions

Woocommerce Subscriptions get next payment date when subscription is renewed


I’m using Woocommerce Subscriptions plugin in my Woocommerce site. I want to post the new renewal date for a subscription to an external API when a subscription is renewed. I’m trying to use the ‘woocommerce_subscription_renewal_payment_complete’ action hook so whenever a subscription is renewed I can access the $subscription object and the $last_order object. But when I try to get the $subscription->get_date(‘nex_payment’) date, it will always return the last renewal date and not the next renewal date. I looks like the $subscription has not really been updated before this hook and the ‘next_payment’ date is still not updated to the next value when firing this action hook.

Does anybody know how to get the real ‘next_payment’ date after a renewal has been completed?

Thank you!


Solution

  • for those that could be interested in a solution, I've finally found that there's an action hook called 'woocommerce_subscription_date_updated' that fires when a date of the subscription has been updated.

    Simply add an action to this hook:

    <?php
    add_action('woocommerce_subscription_date_updated', 'subscription_date_update', 10, 3);
    
    function subscription_date_update($subscription, $date_type, $datetime)
    {
      //Do your stuff here...
    }