如何在 woocommerce 电子邮件模板中显示客户姓名?

How to display customer name in woocommerce email template?

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

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

[HEADER]You order has been placed [/HEADER]

[H2]Hi {CUSTOMER_NAME}[/H2]

[P]Some text[/P]

[THE REST OF THE MAIL]

我试过在我的主题 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>';

    }

}

但这行不通。 有人可以帮忙吗?

试试这个 ::

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>';
}
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 片段