Support » Plugin: WooCommerce » username not displaying at all in new account email

  • Hello, I use this to display username (nickname) of a customer:

    <?php $username = get_userdata($order->user_id)->user_login; ?>
    <p>Your username is:</p>
    <p> <?php echo $username; ?> </p>

    Unfortunately, when put in customer-new-account.php template, the username is not displayed in generated email.
    I tested the same code in thankyou.php template and it successfully showed on the page after purchase.
    So the problem is to get it to work for emails.


Viewing 7 replies - 1 through 7 (of 7 total)
  • $order will be null inside customer-new-account.php as the order has still not been placed at the time of registration. So the following line will not work

    <?php $username = get_userdata($order->user_id)->user_login; ?>

    Just checked the default customer-new-account.php template and it does display the username

    <p><?php printf( __( "Thanks for creating an account on %s. Your username is <strong>%s</strong>.", 'woocommerce' ), esc_html( $blogname ), esc_html( $user_login ) ); ?></p>

    Thank You for clarification. I tried to change a default account creation text. First I tried echoing:
    esc_html( $user_login )
    However opposed to default behaviour of the code that You posted, it shows user email, not his username, so I’m not sure why it happens or how to fix it.

    Plugin Author Mike Jolley


    Are you sure the user name is not his email? Check the account.

    Good point, it appears that at the moment all created accounts have email as login:
    wp_users table: user_login:
    wp_usermeta table: meta_key: nickname, meta_value:

    I have an option “Automatically generate username from customer email” in WooCommerce settings (accounts tab) NOT checked.

    Account is created only during checkout, with username specified in inputbox #account_username. As I mentioned earlier I was able to return nickname entered in this inputbox using get_userdata($order->user_id)->user_login
    on thankyou.php template.

    The problem seems to be that nickname entered is not used while creating a new account.

    Plugin Author Mike Jolley


    They must be registering elsewhere if you have a username field, assuming thats not custom.

    That does however mean your snippet earlier is fine 🙂

    Please fix this, its come with update from 25 may I think. I have couple sites and user with new update do not receive username. What will be worse they receive only blogname as username

    <p><?php printf( __( “Thanks for creating an account on %s. Your username is %s.”, ‘woocommerce’ ), esc_html( $blogname ), esc_html( $user_login ) ); ?></p>

    so I temporarly changed it to

    <p><?php printf( __( “Thanks for creating an account “, ‘woocommerce’ ), esc_html( $user_login ) ); ?></p>

    so they dont receive blog username. Something is wrong, this variable didnt pass to email template, its empty.

    Plugin Author Mike Jolley


    Look at your translation files perhaps. user_login is in your code, and it works my side.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘username not displaying at all in new account email’ is closed to new replies.