[SOLVED] How to trigger emails of Failed Orders in WooCommerce

Update on February 3rd, 2016:

As of version 2.5 of WooCommerce, this functionality is now built into the WC Core. This plugin is not needed. See the WC 2.5 Changelog for more details.

 

Following the lead from this blog post by SkyVerge, I set upon to create email notifications when an order fails. Essentially, any time the credit card fails or the order processing is not successful, WooCommerce should notify the store owner that the order has failed.

Currently, WooCommerce is silent about Failed Orders. Note that there is a built in setting in WooCommerce for notifications about Canceled Orders, but not Failed Orders.

My first attempt at trying to modify this plugin by Justin Stern, failed. I tried to adapt the plugin for “Failed” instead of “Cancelled”. However, just replacing the instances of “Canceled” with “Failed” did not accomplish my objective.

After a lot of experimenting, I gave up and sought the help from the WooCommerce community. One of the most helpful WooNinjas, Caleb Burks, lent me a hand for this one. I take no credit for this. All I can say is that guy knows his coding very well.

In the future, I will try to explain the code. For now, here is the link to the completed plugin that sends out emails immediately after an order transitions into Failed status. To test this, simply change the status of an order to “Failed”. Emails should be fired off to the store owner.

Good luck to you. Let me know if it works or if you experience problems. This does work on my setup: WordPress 4.3.1, WooCommerce 2.4.6.

 

6 Replies to “[SOLVED] How to trigger emails of Failed Orders in WooCommerce”

  1. Thank you so much for sharing! This was very helpful on a recent project. I was rebuilding the code myself, but now that I found this, I can move onto other things instead of wasting my time. Thanks again!

  2. Thanks for informative article. I am wondering how can I accomplish custom email for custom order status. I have looked through many articles but not find any satisfactory answer. Help would be appreciated.

    1. @Chirag
      I think it should be fairly straightforward to extend this example code to suit it for your needs. If you have created the custom order status, you just need to fire off the appropriate action hooks to trigger the custom emails.

Leave a Reply

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