WooCommerce Get User Details By User ID

Hi Guys,

In WooCommerce, you can fetch all the user details by user id using get_user_meta() function.
If you want to get the user details by user id, you can use the following code snippet:

$customer_id = '10';
$customerData = get_user_meta($customer_id);
$first_name = isset($customerData['first_name'][0]) ? $customerData['first_name'][0] : '';
$last_name = isset($customerData['last_name'][0]) ? $customerData['last_name'][0] : '';
$companyName = isset($customerData['billing_company'][0]) ? $customerData['billing_company'][0] : '';
$billing_address_1 = isset($customerData['billing_address_1'][0]) ? $customerData['billing_address_1'][0] : '';
$billing_city = isset($customerData['billing_city'][0]) ? $customerData['billing_city'][0] : '';
$billing_postcode = isset($customerData['billing_postcode'][0]) ? $customerData['billing_postcode'][0] : '';
$billing_state = isset($customerData['billing_state'][0]) ? $customerData['billing_state'][0] : '';
$phone = isset($customerData['billing_phone'][0]) ? $customerData['billing_phone'][0] : '';
$billing_email = isset($customerData['billing_email'][0]) ? $customerData['billing_email'][0] : '';

That’s it! You are done.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s