繁体   English   中英

根据 Woocommerce 中的运输方式向客户通知添加回复电子邮件

[英]Add a reply email to customer notifications based on shipping methods in Woocommerce

所有订单电子邮件都从默认的 woocommerce 电子邮件地址发送给客户,例如webshop@shop.com ,这是可以的,但我想为这些电子邮件添加回复电子邮件地址,以便用户能够回复此自定义地址,例如reply@webshop.com

我还想根据$order运输方式设置此回复电子邮件地址。 如果送货方式是' local_pickup_plus ',请将回复地址设置为reply1@webshop.com ,否则设置reply2@webshop.com

我发现,我可以使用woocommerce_email_headers过滤器修改标题,但仅限于发送给管理员的电子邮件。

add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 3);
function mycustom_headers_filter_function( $headers, $object, $order ) {
    if ($object == 'new_order') {
        $headers .= 'Reply-to: teszt@teszt.hu';
    }

    return $headers;
}

如何为客户电子邮件设置此项?

以下代码将允许您根据客户电子邮件通知的运输方式有条件地添加不同的回复电子邮件:

// Utility function to get the shipping method Id from order object
function wc_get_shipping_method_id( $order ){
    foreach ( $order->get_shipping_methods() as $shipping_method ) {
        return $shipping_method->get_method_id();
    }
}

// Add coditionally a "reply to" based on shipping methods IDs for specific email notifications
add_filter( 'woocommerce_email_headers', 'add_headers_replay_to_conditionally', 10, 3 );
function add_headers_replay_to_conditionally( $headers, $email_id, $order ) {
    // Avoiding errors
    if ( ! is_a( $order, 'WC_Order' ) || ! isset( $email_id ) )
        return $headers;

    // The defined emails notifications to customer
    $allowed_email_ids = array('customer_on_hold_order', 'customer_processing_order', 'customer_completed_order');

    // Only for specific email notifications to the customer
    if( in_array( $email_id, $allowed_email_ids ) ) {
        // Local Pickup Plus shipping method
        if( wc_get_shipping_method_id( $order ) === 'local_pickup_plus' ){
            $headers .= "Reply-to: reply1@webshop.com". "\r\n"; // Email adress 1
        } 
        // Other shipping methods
        else {
            $headers .= "Reply-to: reply2@webshop.com". "\r\n"; // Email adress 2
        }
    }

    return $headers;
}

代码位于活动子主题(活动主题)的 function.php 文件中。 测试和工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM