Skip to content

Instantly share code, notes, and snippets.

@madeincosmos
Created May 23, 2019 10:11
Show Gist options
  • Save madeincosmos/d947066af056fd033a3c2ed01b1c9eb6 to your computer and use it in GitHub Desktop.
Save madeincosmos/d947066af056fd033a3c2ed01b1c9eb6 to your computer and use it in GitHub Desktop.
Add customer username and ID to WooCommerce emails
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;
}
@neilphil
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment