Sometime we need to check the condition if customer is logged in or not:

/** @var \Magento\Framework\App\ObjectManager $ */
$obm = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Framework\App\Http\Context $context */
$context = $obm->get('Magento\Framework\App\Http\Context');
/** @var bool $isLoggedIn */
$isLoggedIn = $context->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);

Once you have the $isLoggedIn variable, you can check condition as per below.

<?php if($isLoggedIn): ?>

//your condition code

<?php else: ?>

//your condition code

<?php endif; ?>

Categories: Magento2

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *