How to check If Customer is Logged In or Not Magento 2?

  • author-img Nidhi Arora
  • 7 years
How to check If Customer is Logged In or Not Magento 2?

Method 1. To check the customer is logged or not on any page of the website:

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

$customerSession = $objectManager->get('Magento\Customer\Model\Session');

if($customerSession->isLoggedIn()) {

   // customer login action

}

Method 2.  To check if customer is logged from controller:

$this->_objectManager->get('Magento\Customer\Model\Session');

if($customerSession->isLoggedIn()) {

   // customer login action

}

If you still have any query regarding this “How to” or would like to add some suggestions to this solution, let us know your feedback or query at sales@envisionecommerce.com, and don’t forget to share this “How to” blog with your fellow Magento 2 users!

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