i want to have a text and a button in home page when customer is not logged in and when he is logged in this block (div) should be hidden so how to proceed? any help please

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
   // customer login 
}else{
 // customer not login 
}
  • i tried this but not working – Developper Magento Dec 7 at 9:05
  • share your code – Jimit Bhavsar Dec 7 at 9:07
  • <?php $objectManagerlogin = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManagerlogin->get('Magento\Customer\Model\Session'); $baseurl = $objectManagerlogin->get('Magento\Store\Model\StoreManagerInterface')->getStore(0)->getBaseUrl(); ?> <?php if($customerSession->isLoggedIn()) :?> <div id="content"> <?php echo "hello" ;?> </div> <?php endif;?> – Developper Magento Dec 7 at 9:08
  • Try reversing the condition. Means add a ! (Not sign) before $customerSession->isLoggedIn(). – Mohit Kumar Arora Dec 7 at 9:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.