Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce failed order email notification
<?php
/**
* Add a failed order email notification
*/
function sp_failed_order_email_notification( $order_id ) {
$order = wc_get_order( $order_id );
$to = get_option( 'admin_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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.