Add a new field to woocommerce_email_customer_details or any other part of emails

10,609

We can adapt from my tutorial on customizing the checkout fields to display some extra info in the email:

function kia_display_email_order_user_meta( $order, $sent_to_admin, $plain_text ) {
    $user_id = $order->customer_user;
    if( ! empty( $user_id ) && ( $data = get_user_meta( $user_id, '_some_user_meta', true ) ) != '' ){
        if( $plain_text ){
            echo 'The user data for some field is ' . $data;
        } else {
            echo '<p>The user data for <strong>some field</strong> is ' . $data . '</p>';
        }
    }    
}
add_action('woocommerce_email_customer_details', 'kia_display_email_order_user_meta', 30, 3 );

In this case we'll replace the get_post_meta() of my tutorial with get_user_meta().... and knowing that the user Id is stored in the $order->customer_id property of the $order object.

Share:
10,609
Admin
Author by

Admin

Updated on July 01, 2022

Comments

  • Admin
    Admin almost 2 years

    Ok so I am building a woocommerce site for a client and they love it but the only issue is they need a customer number to come through with the email for all new orders. They are willing to go in and fill in this info for each user, but I cannot find out how to get this info to automatically send with the new order email.

    I am using WP - Members plugin to add custom information to the users profile, and have created a field there called Customer # (option name: customer_number) I cannot figure how to get woocommerce to add this number to the email that is sent when they place the order (to the admin)

    I have tried many different things, it seems like it should just be a hook but I dont know how to get the values or have not been able to figure this out yet in any way.

    I have looked and looked and this is my last resort, my minimal understanding of php and hooks is probably my downfall here, so please be very clear if instructing me in that way.

    I will not give up on this issue, so I hope someone can help!