Skip to content

Instantly share code, notes, and snippets.

@twoelevenjay
Created July 20, 2014 21:46
Show Gist options
  • Save twoelevenjay/fe40054f6865ce93ae3f to your computer and use it in GitHub Desktop.
Save twoelevenjay/fe40054f6865ce93ae3f to your computer and use it in GitHub Desktop.
Function to have WooCommerce send an automatic support email to the customer for orders that switch to a status of cancelled.
<?php
add_action('woocommerce_order_status_changed', 'send_support_email');
function send_support_email($order_id) {
$order_data = new WC_Order($order_id);
global $woocommerce;
$mailer = $woocommerce->mailer();
if ($order_data->status=='cancelled') {
$to = $order_data->billing_first_name . ' <' . $order_data->billing_email . '>';
$subject = 'Trouble with order #' . $order_id;
$message = $mailer->wrap_message('Trouble with order #' . $order_id, 'We noticed that your recent order was cancelled. As a courtesy we wanted to make sure that you did not need any assistance. If you do please contact us by replying to this email. Otherwise you do not need to do anything.');
woocommerce_mail( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment