Woocommerce - Bcc email only when the admin is rec

2019-06-10 05:33发布

How to Get email recipient to make an conditional function to add extra bcc email header on email only to admin OR by Order Status?

add_filter( 'woocommerce_email_headers', 'profit_extra_email', 10, 2);
function profit_extra_email( $headers ) {
    $headers .= 'BCC: Vendas Promocional Fitness <eu@site.com>' . "\r\n";
    return $headers;
}

This function above work, but bcc email retrieve all emails. I need retrieve only emails to admin OR by Order Status.

Help any!! :O

1条回答
2楼-- · 2019-06-10 05:56

There are 3 variables passed to the woocommerce_email_headers filter. Since none of them appear to be the $in_admin variable that is passed to templates, we have to take a different approach. The second param is $email_id which is a unique identifier for each email class. Therefore we can make an array of all the admin emails and check if the current email is in that array. If so, add your CC.

function so_31737121_email_headers( $headers, $email_id, $order ){
    $admin_emails = array( 
        'low_stock',
        'no_stock',
        'backorder',
        'cancelled_order',
        'new_order'
    );

    if( in_array( $email_id, $admin_emails ) ){
        $headers .= 'BCC: Vendas Promocional Fitness <eu@site.com>' . "\r\n";
    }
    return $headers;
}
add_action( 'woocommerce_email_headers', 'so_31737121_email_headers', 10, 3 );
查看更多
登录 后发表回答