How to Get Logged In Customer Details in Magento2

In this tutorial, we will show how you can get the logged in customer details in Magento2. After the successful login the customer information will be stored in $om->get('Magento\Customer\Model\Session'); customer session object.

The the best way is to get logged in customer in any place is use Magento \Customer\Model\Session model , we are going to use magneto object manager to access to session model as follow.

Get Logged In User Details:

The below php script will return the logged in user details.

$om = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $om->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
echo $customerSession->getCustomer()->getId()."<br/>";  // get Customer Id
echo $customerSession->getCustomer()->getName()."<br/>";  // get  Full Name
echo $customerSession->getCustomer()->getEmail()."<br/>"; // get Email Name
echo $customerSession->getCustomer()->getGroupId()."<br/>";  // get Customer Group Id
echo $customerSession->getCustomer();
echo $customerSession->getCustomerData();
(Visited 23 times, 1 visits today)
Chandra Kumar

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of

0 Comment

Leave a Comment

Your email address will not be published. Required fields are marked *