【问题标题】:How to display customer name in woocommerce email template?如何在 woocommerce 电子邮件模板中显示客户姓名?
【发布时间】:2017-05-09 17:14:46
【问题描述】:

我是 Woocommerce 的新手,我正在尝试在电子邮件的开头显示客户的姓名。

因此电子邮件将如下所示:

[HEADER]您的订单已下达[/HEADER]

[H2]嗨{CUSTOMER_NAME}[/H2]

[P]一些文字[/P]

[邮件的其余部分]

我已经尝试在我的主题中的 functions.php 中添加类似的内容。

//add the first name of the person to the email. 
add_filter('woocommerce_email_order_details','name_to_processing_customer_email', 10, 3);
function name_to_processing_customer_email( $order, $sent_to_admin, $plain_text, $email ) {

    if( 'customer_processing_order' == $email->id ){

        // Set here as you want your custom content (for customers and email notification related to processing orders only)
        echo '<h2>Hej '.$order->billing_first_name .'</h2>';

    }

}

但这不起作用。 有人可以帮忙吗?

【问题讨论】:

    标签: wordpress email woocommerce customer


    【解决方案1】:

    试试这个 ::

    add_filter('woocommerce_email_order_details','name_to_processing_customer_email', 10, 3);
    function name_to_processing_customer_email( $order_id, $sent_to_admin, $plain_text, $email ) {
        $order = new WC_Order( $order_id );
        echo '<h2>Hej '.$order->billing_first_name .' '.$order->billing_last_name.'</h2>';
    }
    

    【讨论】:

    • 它有效。但是位置不正确。文本出现在订单项目的正上方,我想在邮件标题之后。
    【解决方案2】:
    add_action( 'woocommerce_email_after_order_table', 'name_to_processing_customer_email', 10, 2 );
    function name_to_processing_customer_email( $order, $is_admin_email ) {
        echo '<p><h4>Shipping:</h4> ' . $order->get_billing_first_name() . '</p>';
    }
    

    检查这个 WC3 sn-p

    【讨论】:

      猜你喜欢
      • 2021-09-27
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 2018-04-24
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多