Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save full-stack-king/fbc887c3432a6f746cc3 to your computer and use it in GitHub Desktop.
Save full-stack-king/fbc887c3432a6f746cc3 to your computer and use it in GitHub Desktop.
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