Created
May 23, 2019 10:11
-
-
Save madeincosmos/d947066af056fd033a3c2ed01b1c9eb6 to your computer and use it in GitHub Desktop.
Add customer username and ID to WooCommerce emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_email_customer_details_fields', 'add_user_id_to_woocommerce_emails', 10, 3); | |
function add_user_id_to_woocommerce_emails( $fields, $sent_to_admin, $order ) { | |
$user_id = $order->get_customer_id(); | |
$user_info = get_userdata( $user_id ); | |
$fields['user_id'] = array( | |
'label' => __( 'User ID', 'woocommerce' ), | |
'value' => $user_id | |
); | |
$fields['username'] = array( | |
'label' => __( 'Username', 'woocommerce' ), | |
'value' => $user_info->user_login | |
); | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
This works well for me. Is there a way of it only appearing on the admin emails, rather than the ones that go out to the customers?
Thank You