We have a situation in a Woocommerce Subscriptions set up where the default sync options won't work. I've created a manual calendar that my functions.php
file references at subscription creation time, but it only ever checks at subscription creation and then the plugin automatically sets the next renewal to be every 4 weeks thereafter.
I need to fire my renewal date checker function after each subscription creation and/or renewal to calculate the next renewal date from my calendar. I know there are at least two hooks I could try, being:
wcs_renewal_order_created
and woocommerce_subscription_payment_complete
, but I don't know enough about when those are triggered to know which is the safest.
About woocommerce_subscription_payment_complete
, the WC Subscriptions documentation says:
Triggered when a payment is made on a subscription. This can be payment for the initial order or a renewal order. It is important to note, however, that subscription date changes related to early renewals are processed differently than other renewals, so this action should not be relied upon for capturing the next payment date on a subscription.
I'm not 100% sure what case they refer to in their note, but it was enough to give me pause.
About wcs_renewal_order_created
, I am unclear as to when this fires:
These orders are always created through the wcs_create_renewal_order() function, regardless of whether they are created for a scheduled renewal event, manually via the WooCommerce > Edit Subscription administration screen, or via the Subscriptions endpoints for the WooCommerce REST API. Because of this, itβs possible to add, remove or update the value of anything on that renewal order using this filter.
For example, this can be used to add a discount to specific renewal orders, like the 12th order each year. It could also be used to add one-time fee for a certain renewal order, like a special annual extra fee on a monthly subscription.
Would trying to set the next_date
key via update_dates()
during this hook push the current payment it was about to process or has it already happened and so setting the next date is now safe?
What is the most reliable way to set the next renewal date programmatically immediately after the current period has been processed for a given subscription?