Juice Khow
Juice Khow

Reputation: 43

Send on-hold order status email notification to admin

I want the admin to receive on hold order notification as well in WooCommerce. Right now, only customers get that notification.

I have tried the following codes but it doesn't seem to work.

Here is my code:

add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
function mycustom_headers_filter_function( $headers, $object ) {
    if ($object == 'customer_on_hold_order') {
        $headers .= 'BCC: My name <[email protected]>' . "\r\n";
    }
    return $headers;
}

What should be the correct filter/hook to use?

Thanks

Upvotes: 4

Views: 3981

Answers (3)

Droid Sheep
Droid Sheep

Reputation: 11

The correct $email_id for "on-hold" order status email notification is NOT 'customer_on-hold_order' as sugested in the answer bellow (sorry no reputation to comment) but the right one is 'customer_on_hold_order'

So change the on-hold to on_hold

Upvotes: 0

contemplator
contemplator

Reputation: 358

It has been 3 years and the WooCommerce states seem to have changed. I tried using the new states customer_on-hold_order => pending_to_on-hold or woocommerce_order_status_pending_to_on-hold, but no emails came and the headers were not changed. so I resulted in just using single words for the check:

// Send on-hold order status email notification to admin
add_filter( 'woocommerce_email_headers', 'custom_admin_email_notification', 10, 3);
function custom_admin_email_notification( $headers, $email_id, $order ) {

    if( strpos($email_id,'hold') > 0 ){
        $headers .= 'Bcc: Admin User <[email protected]>'. "\r\n";
    }
    return $headers;
}

I thank you @LoicTheAztec, however for pointing me in the right direction.

Upvotes: 0

LoicTheAztec
LoicTheAztec

Reputation: 253784

The correct $email_id for "on-hold" order status email notification is 'customer_on-hold_order'.

So your code is going to be:

add_filter( 'woocommerce_email_headers', 'custom_admin_email_notification', 10, 3);
function custom_admin_email_notification( $headers, $email_id, $order ) {

    if( 'customer_on-hold_order' == $email_id ){
        // Set HERE the Admin email
        $headers .= 'Bcc: My name <[email protected]>\r\n';
    }
    return $headers;
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Code is tested and works.


Similar answers: How to get order ID in woocommerce_email_headers hook

Upvotes: 2

Related Questions