[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.

 


Posted

in

, ,

by

Comments

11 responses to “[SOLVED] How to trigger emails of Failed Orders in WooCommerce”

  1. Tyler Johnson Avatar

    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. Amit Ramani Avatar

    Woocommerce 2.5 supports the Admin Failed Order Notification feature. This plugin is no longer needed and can safely be deactivated/deleted.

  3. Chirag Avatar
    Chirag

    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. Amit Ramani Avatar

      @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.

  4. Biography Avatar

    I m not looking for admin notification, how to setup notification for buyer if the order fails.

    1. Amit Ramani Avatar

      All you have to do is change the recipient email address. It should work. The code still stays the same.

  5. Santiago Valdes Avatar
    Santiago Valdes

    Thanks Amit!

    I want to send an email to customers when their orders change to cancelled (from pending, on hold or failed) because of no payment.

    Is this the best way still to do it, creating a new email class for that?

    I have it working right now with a few alterations, but I wonder if it’s the best way to do it 4 years later?

    Thanks!

    1. Amit Ramani Avatar

      Hi Santiago
      Sorry for the late reply. To the best of my knowledge, this method still works. Did you find otherwise? I am sorry I can not answer whether this is the ideal way to do this.

  6. Sheena Avatar
    Sheena

    Hi, is it possible to automatically send out email to the customer whose order failed?

    1. Amit Ramani Avatar

      Hi Sheena
      Yes, that can be accomplished via custom programming.

  7. Tayssir Avatar
    Tayssir

    Hello, do you have any solution, how to send email if the status changed from “ANY” to wc-order-confirmed ?

Leave a Reply to Tayssir Cancel reply

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