Custom “reply to” email header in Woocommerce New Order email notification

无人久伴 提交于 2019-12-19 09:39:19

问题


I'm looking to filter the email headers of the new order form in woocommerce. I'm trying to replace the customer email address with the main site admin email address. We need to do this because Gmail is flagging new orders as spam because the from address is not the same as the reply to address. The function below works partially:

add_filter( 'woocommerce_email_headers', 'woo_add_reply_to_wc_admin_new_order', 10, 3 );

function woo_add_reply_to_wc_admin_new_order( $headers = '', $id = '', $order ) {
if ( $id == 'new_order' ) {
    $reply_to_email = get_option( 'admin_email', '' );
    $headers .= "Reply-to: <$reply_to_email>\r\n";
}
return $headers;}

This function is adding the site admin email address but doesn't remove the customer email.

Anyone out there have any ideas on how to remove the customer email from the reply to field? Note: We still need to have a record of the customer email on the order - we just don't want it in the email headers

Any help would be great!


回答1:


The correct way to make it work is:

add_filter( 'woocommerce_email_headers', 'new_order_reply_to_admin_header', 20, 3 );
function new_order_reply_to_admin_header( $header, $email_id, $order ) {

    if ( $email_id === 'new_order' ){
        $email = new WC_Email($email_id);
        $header = "Content-Type: " . $email->get_content_type() . "\r\n";
        $header .= 'Reply-to: ' . __('Administrator') . ' <' . get_option( 'admin_email' ) . ">\r\n";
    }
    return $header;
}

This code goes on function.php file of your active child theme (or theme). Tested and works.



来源:https://stackoverflow.com/questions/49171568/custom-reply-to-email-header-in-woocommerce-new-order-email-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!