How to get logged in customer data in Magento2?

  • Nidhi Arora
  • 4 years
How to get logged in customer data in Magento2

First you need to create a object instance:

?$om = \Magento\Framework\App\ObjectManager::getInstance();

After that:

    $customerSession = $om->get('Magento\Customer\Model\Session');
    if($customerSession->isLoggedIn()) {
        echo   $customerSession->getCustomer()->getId()."
";  // get Customer Id
        echo   $customerSession->getCustomer()->getName()."
";  // get  Full Name
        echo   $customerSession->getCustomer()->getEmail()."
"; // get Email Name
        echo   $customerSession->getCustomer()->getGroupId()."
";  // get Customer Group Id

Though, if you find difficult or need more clarity regarding this “How to” or would like to add some suggestions to this solution, do drop a comment below or query at [email protected]. Our certified Magento team will give you a positive solution to all your Magento related queries with positive ROI!

Join us for a FREE webinar