【问题标题】:Add a reply email to customer notifications based on shipping methods in Woocommerce根据 Woocommerce 中的运输方式向客户通知添加回复电子邮件
【发布时间】:2019-04-16 03:27:17
【问题描述】:

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

我还想根据$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;
}

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

【问题讨论】:

    标签: php wordpress woocommerce email-headers email-notifications


    【解决方案1】:

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

    // 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 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 2018-02-15
      • 2021-07-20
      • 2017-12-06
      相关资源
      最近更新 更多