Skip to content

Instantly share code, notes, and snippets.

@mateusneves
Created May 8, 2018 14:40
Show Gist options
  • Save mateusneves/cf865858cab4db3e5e6e63c39069c1c7 to your computer and use it in GitHub Desktop.
Save mateusneves/cf865858cab4db3e5e6e63c39069c1c7 to your computer and use it in GitHub Desktop.
Woocommerce fail order send email
<?php
/*
* Woocommerce send email to customer when order status is change to Failed
*/
add_action( 'woocommerce_order_status_failed', 'mysite_failed');
function mysite_failed($order_id) {
error_log("$order_id set to FAILED", 0);
$order = wc_get_order( $order_id );
// User data
$user_email = $order->get_billing_email();
// From data
$email = '[email protected]';
$message = 'Fail order!';
// To data
$to = $user_email;
$subject = "Fail Order";
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
// Send email
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
if($sent){
}// Message send
else {
}// Message not send
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment