This is my code,
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');
if ($customerSession->isLoggedIn()) {
$customerSession->getCustomerId(); // get Customer Id
$customerSession->getCustomerGroupId();
$customerSession->getCustomer();
$customerSession->getCustomerData();
$myemail=(string)$customerSession->getCustomer()->getEmail();
echo $myemail;
same code I run Custom module its getting customer email , but, I paste same code other magento core module, Now if condition failed if($customerSession->isLoggedIn())
why? how to solve this problem.
Best Answer
I am facing same problem when Cache enable I am not able to get customer session.But I find below solution
Use above code in block It is working even cache is enable.
Second Solution:
Add cacheable="false" in your xml
Add below code in block: