How to get logged in customer data in Magento2?

  • author-img Nidhi Arora
  • 7 years

First you need to create a object instance:

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

After that:

?php
    $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 sales@envisionecommerce.com. Our certified Magento team will give you a positive solution to all your Magento related queries with positive ROI!

Download Blog

ENQUIRY

Ready to Get Started

Communication is the key for us to understand each other. Allow us to understand
your requirements or queries. Present us with an opportunity to serve you.

Fill out the form and out team will get back to you
within 24 hours

    Head Office

    815 Brazos St STE 500, Austin,
    TX 78701, USA