Wordpress - get_user_meta() doesn't include user email?
Just wanted to let you know you have get_user_meta
and get_userdata
. The email address can be found using the get_userdata
function.
For the current user this code can apply:
<?php
$user_id = get_current_user_id();
$user_info = get_userdata($user_id);
$mailadresje = $user_info->user_email;
echo $mailadresje;
?>
Please note this is applicable to the current user. If you need to get the user_id
of let's say an order you need the following code (which I used to display the users mail on the invoice in WooCommerce) :
<?php
$user_id = $wpo_wcpdf->export->order->user_id;
$user_info = get_userdata($user_id);
$mailadresje = $user_info->user_email;
echo $mailadresje;
?>
Happy programming!
get_user_meta
retrieves a single meta field or all fields of the user_meta
data for the given user.
This means that all the values that are stored in user_meta
table can be got using get_user_meta
. Email is not stored as meta data so you cant get email using get_user_meta
.
Email is stored with username and password in user
table as user data.