Support » Plugin: WooCommerce » Add username in email confirmation

  • Resolved massidrink1976

    (@massidrink1976)


    Hi!

    I would like to add the “username” field in the order confirmation email.
    For example:

    <<You have received the following order from “Name and Last name” (Username)>>

    Do you know how to do it?

    Best regards,
    Max

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Stef

    (@serafinnyc)

    You can customize the templates by overriding them. Here is the structure you would need to add to your theme.
    https://docs.woocommerce.com/document/template-structure/

    Edit the admin-new-order.php

    Plugin Support Job

    (@jobthomas)

    Automattic Happiness Engineer

    Hi @massidrink1976 – you can do this by following the same approach as Con suggested in this thread here: https://wordpress.org/support/topic/how-to-add-user-first-name-and-user-name-to-email-body/

    This function reference has the way you can pull a username from a WordPress site: https://codex.wordpress.org/Function_Reference/get_userdata

    <?php $user_info = get_userdata(1);
          echo 'Username: ' . $user_info->user_login . "\n";
          echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
          echo 'User ID: ' . $user_info->ID . "\n";
    ?>

    A combo of the two tutorials should do the trick for you.

    Plugin Support Job

    (@jobthomas)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    massidrink1976

    (@massidrink1976)

    Hello I’m sorry,

    I didn’t work over the weekend…luckily 🙂

    I added this code in “admin-new-order”:

    do_action( ‘woocommerce_email_header’, $email_heading, $email ); ?>

    <?php /* translators: %s: Customer billing full name */ ?>
    <?php $user_info = get_userdata(1);
    echo ‘Kundennummer: ‘ . $user_info->ID . “\n”;
    ?>

    but something is wrong.

    In the confirmation email, “1” appears instead of my username “132064”

    I tried also another version:

    do_action( ‘woocommerce_email_header’, $email_heading, $email ); ?>

    <?php /* translators: %s: Customer billing full name */ ?>
    <?php $user_info = get_userdata(1);
    echo ‘Username: ‘ . $user_info->user_login . “\n”;

    ?>

    but in this case, appear “admin”.

    Regards,
    Massimiliano

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add username in email confirmation’ is closed to new replies.