Streamlining WooCommerce Subscriptions: Automated Handling of Failed Renewal Orders


In a recent deep dive into WooCommerce Subscriptions, we found ourselves grappling with the intricacies of failed payment retry rules, seeking to optimize their functionality for a valued client.

These rules, pivotal within the WooCommerce Subscriptions plugin, dictate the course of action when a subscription renewal payment encounters a stumbling block. The specific challenge on our hands was devising a mechanism to automatically cancel subscriptions after a specified period, following the exhaustion of all retry rules without a successful payment.

Unfortunately, the existing retry rules lacked this particular functionality, as the subscription status is left on hold, the customer is sent an email notifying them of the failed payment, and the order payment is flagged as failed.

Our solution involved interfacing with the retry rule process. Once all retry rules were exhausted, we implemented a scheduled task to update the subscription after a predefined duration, contingent upon specific conditions being met.

Initially, we employed a hook within WooCommerce Subscriptions triggered after a payment retry is processed. Within this function, we ensured the order still required payment before proceeding. Using the given order, we traversed through all attached subscriptions, verified the absence of scheduled retry rules, appended an order note for clarity, and scheduled an event to run in 4 weeks, passing in the subscription ID and order ID:

When the scheduled event executes, the subsequent function is activated. We initiate a check on the order to determine if it had been marked as “failed” (a status set by the final retry rule), enabling us to exit the process early if necessary. A couple of checks on the subscription ensure its continued existence in the system and that it had been marked as “on-hold” (set by the last retry rule). We then update the subscription status to “cancelled” if required, appending a note for clarity:

This approach ensures a seamless and automated process for handling unsuccessful subscription payments, offering a more efficient and user-friendly experience for WooCommerce store owners.


Leave a Reply

Your email address will not be published. Required fields are marked *