简体   繁体   中英

Add customer email address to new account email notification in WooCommerce

I am trying to insert the customer email address in "new account" email.

So far I tried using $user_email instead of $user_login and $order->billing_email in a hook but it shows blank space every time.

Updated: You can use a custom function hooked in woocommerce_email_header action hook:

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

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested and works.


Or you can insert in the template emails/customer-new-account.php the following code, in the location of your choice:

<?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>';
?>

Tested and works.

Official documentation: Overriding WooCommerce templates via a theme

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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