If you are beginner wordpress Plugin or don’t know how to get logged in user details in wordpress woocommerce web application then you can do it using wordpress WP_User(), wp_get_current_user(), get_user_by( ‘ID’, $current_user->ID ), get_userdata( $current_user->ID ) and get_currentuserinfo(). wordpress can get current login user data both way one using auth wp_get_current_user() and another get_userdata(). In this article you can learn how to get current logged user id, get current user role, get current login user id in php wordpress, get user meta. so first you.
4 Ways To Get Logged User Data
Depending on whether you have the woocommerce current user’s ID (If not, checkout: get current login user id in php wordpress) you can get the user display name, first name, last name, Username, User email or More details by creating the current user object first of all:
How to get current user details in WordPress woocommerce?
- Using WP_User()
- Using wp_get_current_user()
- Using get_user_by( ‘ID’, $current_user->ID )
- Using get_userdata( $current_user->ID )
Also You can read My Prev Article for get current user()->id laravel.
How to Get Logged-in User’s Info in WordPress?
ID . "
"; echo 'User first name: ' . $current_user->user_firstname . "
"; echo 'User last name: ' . $current_user->user_lastname . "
"; echo 'User display name: ' . $current_user->display_name . "
"; echo 'Username: ' . $current_user->user_login . "
"; echo 'User email: ' . $current_user->user_email . "
"; } ?>
WordPress get display name
You can use the similar functions to get other Users information about the user such as their login, user ID, Username, email, User first name, User display name, woocommerce website etc.Get display name from user objectWhen the simple user object is created you can easy to obtain the display name from it as bellow Example:
Different ways getting the user object
you can get current login user details using WP_User, it will also return object of current users data.
global $current_user; get_currentuserinfo(); echo 'User ID: ' . $current_user->ID . "
"; // Different ways getting the user object $users_info_way_1 = new WP_User( $current_user->ID ); echo ""; print_r($users_info_way_1); echo "";
// Get display name from user object
$display_name = $users_info_way_1->display_name;
echo $display_name."
";Current user object
you can get current login user details using wp_get_current_user, it will also return object of current users data.
global $current_user; get_currentuserinfo(); echo 'User ID: ' . $current_user->ID . "
"; // Current user object $users_info_way_2 = wp_get_current_user(); echo ""; print_r($users_info_way_2); echo "";
// Get display name from user object
$display_name = $users_info_way_2->display_name;
echo $display_name."
";Get user by ID, email, slug or login
you can get current login user details using get_user_by, it will also return object of current users data.
global $current_user; get_currentuserinfo(); echo 'User ID: ' . $current_user->ID . "
"; // Get user by User ID, User first name, User last name, User display name, email, slug or login $users_info_way_3 = get_user_by( 'ID', $current_user->ID ); echo ""; print_r($users_info_way_3); echo "";
// Get display name from user object
$display_name = $users_info_way_3->display_name;
echo $display_name."
";Get user data by user id
you can get current login user details using get_userdata, it will also return object of current users data.
global $current_user; get_currentuserinfo(); echo 'User ID: ' . $current_user->ID . "
"; // Get user Information by user id $users_info_way_4 = get_userdata( $current_user->ID ); echo ""; print_r($users_info_way_4); echo "";
// Get display name from user object
$display_name = $users_info_way_4->display_name;
echo $display_name."
";Get Current User ID (using PHP)
The simple and great way to get the current logged in user ID with core PHP is to use the get_current_user_id() function. This is the Best solution if you’re creating custom source code as well as required the current login user’s ID Use the source code below to get current user id in woocommerce with WordPress.
Complete Source code: WordPress get User's Information
ID . "
"; echo 'User first name: ' . $current_user->user_firstname . "
"; echo 'User last name: ' . $current_user->user_lastname . "
"; echo 'User display name: ' . $current_user->display_name . "
"; echo 'Username: ' . $current_user->user_login . "
"; echo 'User email: ' . $current_user->user_email . "
"; // Different ways getting the user object $users_info_way_1 = new WP_User( $current_user->ID ); echo ""; print_r($users_info_way_1); echo "";
// Get display name from user object
$display_name = $users_info_way_1->display_name;
echo $display_name."
";// Current user object
$users_info_way_2 = wp_get_current_user();
echo ""; print_r($users_info_way_2); echo "";
// Get display name from user object
$display_name = $users_info_way_2->display_name;
echo $display_name."
";// Get user by User ID, User first name, User last name, User display name, email, slug or login
$users_info_way_3 = get_user_by( 'ID', $current_user->ID );
echo ""; print_r($users_info_way_3); echo "";
// Get display name from user object
$display_name = $users_info_way_3->display_name;
echo $display_name."
";// Get user Information by user id
$users_info_way_4 = get_userdata( $current_user->ID );
echo ""; print_r($users_info_way_4); echo "";
// Get display name from user object
$display_name = $users_info_way_4->display_name;
echo $display_name."
";} ?>
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about woocommerce get current user details.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.