Magento 2 Check customer is logged in– While working on front end we often need to check whether the customer is logged in or not. Here in this tutorial, we are going to explain how to check customer is logged in or not in Magento 2.
Magento 2 Check customer is logged in Example
You can get customer login status using the following method –
Magento 2 Check customer is login Example:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->get('Magento\Customer\Model\Session'); if($customerSession->isLoggedIn()) { // customer login do your stuffs here } |
In the above example we have used object manager to get the current customer session. Using the current customer session object we can get the Login status as above.