将客户电子邮件地址添加到 WooCommerce 中的新帐户电子邮件通知

Add customer email address to new account email notification in WooCommerce

我正在尝试在 "new account" 电子邮件中插入客户电子邮件地址。

到目前为止,我尝试在挂钩中使用 $user_email 而不是 $user_login$order->billing_email,但每次都显示空白 space。

更新: 您可以使用挂钩在 woocommerce_email_header 操作挂钩中的自定义函数:

add_action( 'woocommerce_email_header', 'add_customer_billing_email', 20, 2 );
function add_customer_billing_email( $email_heading, $email )
{
    // Only for  "Customer new account" email notifications
    if( $email->id != 'customer_new_account' ) return;

    // Get user billing email
    global $user_login;
    $user = get_user_by('login', $user_login );
    $email = $user->billing_email;

    // HTML Output
    echo '<p>'.__('Billing email').': <a href="mailto:'.$email.'">'.$email.'</a></p>';
}

代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。

经过测试并且有效。


或者您可以在模板中插入以下代码 emails/customer-new-account.php,在您选择的位置:

<?php
    // Get user billing email
    $user = get_user_by('login', $user_login );
    $email = $user->billing_email;

    // HTML Output
    echo '<p>'.__('Billing email').': <a href="mailto:'.$email.'">'.$email.'</a></p>';
?>

已测试并有效。

官方文档:Overriding WooCommerce templates via a theme