seeker68
seeker68

Reputation: 43

Send customer processing order email notification for on-hold Woocommerce orders

If a customer places an order via bacs gateway, the order status is "on-hold" and the customer recieves the accompanying mail-notification with bank details. After payment is done, customer receives another email - almost with the same content as before: customer_processing_order

My goal:

Disable the mail for on-hold-orders (this is a default function in the backend) and send the email which is actually meant for paid-orders which carry the status "processing" also in case of an order with (on-hold-status) whilst keeping it also in place for customer-processing-orders.

In other words: New orders with status "on-hold" and "processing" should share the same email-template.

Is this somehow possible to achieve?

my rather poor try so far (based on another helpful solution):

function unhook_new_order_processing_emails( $email_class ) {
    // Turn off pending to processing for now
    remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
    // Turn it back on but send the on-hold email
    add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_On_Hold_Order'], 'trigger' ) );
}

Thanks in advance for your help!

Upvotes: 3

Views: 3667

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254362

If you have disabled customer "on-hold" email notifications, you can use the following to send an email notification for on-hold orders status using the "processing" email template:

add_action('woocommerce_order_status_on-hold', 'email_order_processing_status_for_on_hold', 10, 2 );
function email_order_processing_status_for_on_hold( $order_id, $order ) {
    WC()->mailer()->get_emails()['WC_Email_Customer_Processing_Order']->trigger( $order_id );
}

Code goes in function.php file of your active child theme (or active theme). Tested and works

Upvotes: 2

Related Questions