Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Spirecool/45115c9dc442d9bc3c01260d2527f190 to your computer and use it in GitHub Desktop.
Save Spirecool/45115c9dc442d9bc3c01260d2527f190 to your computer and use it in GitHub Desktop.
<?php
// Targets custom order status "refused"
// Uses 'woocommerce_order_status_' hook
add_action( 'woocommerce_order_status_refused', 'bbloomer_status_custom_notification', 20, 2 );
function bbloomer_status_custom_notification( $order_id, $order ) {
$heading = 'Order Refused';
$subject = 'Order Refused';
// Get WooCommerce email objects
$mailer = WC()->mailer()->get_emails();
// Use one of the active emails e.g. "Customer_Completed_Order"
// Wont work if you choose an object that is not active
// Assign heading & subject to chosen object
$mailer['WC_Email_Customer_Completed_Order']->heading = $heading;
$mailer['WC_Email_Customer_Completed_Order']->settings['heading'] = $heading;
$mailer['WC_Email_Customer_Completed_Order']->subject = $subject;
$mailer['WC_Email_Customer_Completed_Order']->settings['subject'] = $subject;
// Send the email with custom heading & subject
$mailer['WC_Email_Customer_Completed_Order']->trigger( $order_id );
// To add email content use https://businessbloomer.com/woocommerce-add-extra-content-order-email/
// You have to use the email ID chosen above and also that $order->get_status() == "refused"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment