Skip to content

How to check customer is logged in or not in Magento 2

Today, we will guide you on how to check whether a customer is logged in or not. Now in this blog, we are going to explain to you how to get the details of the customer which is logged in. There are two ways of getting the dettails of logged in customer details:

Using Block or Helper file, Pass Magento\Framework\App\Http\Context as a dependency to the construct method.

Using Block or Helper file, Pass Magento\Customer\Model\Session as a dependency to construct method.

You can write the following code in template (.phtml) file to check if customer is logged in or not:

Using ObjectManager

Be First to Comment

Leave a Reply

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

Share via
Copy link
Powered by Social Snap