How to get logged in customer data in Magento2?

  • author-img Nidhi Arora
  • 4 years
  • 1,432 views
get logged in customer data in Magento2

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 [email protected]. 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

    1250 Pittsford Victor Road Ste 310
    Pittsford, NY 14534

    Development Center

    Plot no. 10, Rajiv Gandhi
    Chandigarh Technology Park