Skip to content

Instantly share code, notes, and snippets.

@mono96
Created March 3, 2021 14:47
Show Gist options
  • Save mono96/a502fbdee04b5a87a9079d38980db509 to your computer and use it in GitHub Desktop.
Save mono96/a502fbdee04b5a87a9079d38980db509 to your computer and use it in GitHub Desktop.
cancel_mail_to_client_woo.php
/* キャンセル 顧客にメール送信 */
add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );
function send_custom_email_notifications( $order_id, $old_status, $new_status, $order ){
if ( $new_status == 'cancelled' || $new_status == 'failed' ){
$wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects instances
$customer_email = $order->get_billing_email(); // The customer email
}
if ( $new_status == 'cancelled' ) {
// change the recipient of this instance
$wc_emails['WC_Email_Cancelled_Order']->recipient = $customer_email;
// Sending the email from this instance
$wc_emails['WC_Email_Cancelled_Order']->trigger( $order_id );
}
elseif ( $new_status == 'failed' ) {
// change the recipient of this instance
$wc_emails['WC_Email_Failed_Order']->recipient = $customer_email;
// Sending the email from this instance
$wc_emails['WC_Email_Failed_Order']->trigger( $order_id );
}
}
@genepine
Copy link

genepine commented Jun 1, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment