Setup a Failed Order Notification goes to Customer Billing Email for WooCommerce

Published June 21, 2017 by Anil Kumar Vishwakarma

There are various reasons why an Order Failed. The most widely recognised reason is a blunder in the payment processor. This could be a one time thing or possibly a glitch with the payment processor. Regardless it is great to catch up with the client. It would be an immense disgrace on the off-chance that you didn’t do anything as the client was at that point in the checkout/purchasing process and didn’t get the chance to finish their request.

SETTING UP A FAILED ORDER EMAIL NOTIFICATION

There is no user interface for this available in WooCommerce so I’m posting a code snippet you can use. With this code snippet the functionality will be added directly to your site without the use of a plugin. It will automatically send simple email notification with a short message to the Customer Billing email notifying him/her that there has been a failed order.

 

<?php
/**
* Add a failed order email notification
*/
function sp_failed_order_email_notification( $order_id ) {
$order = wc_get_order( $order_id );
$to = $order->billing_email;
$subject = A order failed, action required;
$message = sprintf( __( %1$s went to the `failed` order status. This may require action to follow up., text-domain ), <a class=”link” href=” . admin_url( post.php?post= . $order_id . &action=edit ). “> . sprintf( __( Order #%s, woocommerce), $order->get_order_number() ) . </a> );
$headers[] = From: Me Myself <me@example.net>;
$headers[] = Cc: Some Name <name@email.com>; // Possible CC
$headers[] = Content-Type: text/html;;
$headers[] = charset=UTF-8;
wp_mail( $to, $subject, $message, $headers );
}
add_action( woocommerce_order_status_failed, sp_failed_order_email_notification );
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: