Below script will helpful to find the customer currently logged in a website or not.


$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create(‘Magento\Customer\Model\Session’);
if($customerSession->isLoggedIn()) { //customer is loggedin or not
$customerSession->getCustomer()->getName(); //Loggedin customer Name
$customerSession->getCustomer()->getEmail(); //Loggedin customer Email
//print_r($customerSession->getCustomer()->getData());
}

Or You can try below code


$om = \Magento\Framework\App\ObjectManager::getInstance();
$context = $om->get(‘Magento\Framework\App\Http\Context’);
$isLoggedIn = $context->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
if($isLoggedIn){
echo “Yes Customer loggedin”;
//print_r($context->getData());
}

Hope the post helped you out! Don’t forget to share!

Leave a Reply