Created
April 23, 2021 16:09
-
-
Save Spirecool/45115c9dc442d9bc3c01260d2527f190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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