• I’ve modified the New User Notification Email to include address details entered during the shopping cart of WooCommerce, but I also need to include the first and last name.

    The following code will print the last name matching the hard coded ID…

    $user_last = get_user_meta( 5952, 'last_name', true );
    $message .= sprintf(__('Last Name: %s'), $user_last) . "\r\n\r\n";

    Why does the following not print the last name matching the new users ID?

    $user_last = get_user_meta( $user_id, 'last_name', true );
    $message .= sprintf(__('Last Name: %s'), $user_last) . "\r\n\r\n";

    The following prints the correct ID that I’m trying to target, so this makes little sense to me…

    $message .= sprintf(__('User ID: %s'), $user_id) . "\r\n\r\n";

    If anyone has any suggestions, I’d be very grateful.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    If I’m not mistaken, the new user meta has not yet been stored when the email is sent. You should be able to use the values from $_POST['first_name'] and $_POST['last_name'] in the email.

    Thread Starter rapportdesign

    (@rapportdesign)

    A couple of other forums had lead me to also believe that.

    Thanks for your advice regarding how to get around this.

    I tried…

    $firsttest = $_POST['first_name'];
    $message .= sprintf(__('First Name: %s'), $firsttest) . "\r\n\r\n";

    It still didn’t return anything. ??

    If anyone has any further suggestions, please let me know.

    Moderator bcworkz

    (@bcworkz)

    $_POST[‘first_name’] and $_POST[‘last_name’]

    I’m now not sure why, but I had the WP profile form in my head and that is where the first_name last_name form names came from. You would need to use the actual form names of the fields used on the form that is actually being submitted.

    Apologies for the misdirection, the general idea should work for you though my specifics did not. I don’t know enough about woo to suggest the correct names. You should be able to determine them by examining the HTML page source of the form.

    Thread Starter rapportdesign

    (@rapportdesign)

    That works a treat now… Many thanks!

    I used the following code…

    $firstname = $_POST['billing_first_name'];
    $lastname = $_POST['billing_last_name'];
    $message .= sprintf(__('First Name: %s'), $firstname) . "\r\n\r\n";
    $message .= sprintf(__('Last Name: %s'), $lastname) . "\r\n\r\n";

    Thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘New User Notification Email Include Name’ is closed to new replies.