Check if Customer is Logged in or not in Magento 2

As we all know, there are so many condition where we need to check whether customer is currently logged in or not for specific functionality. In this blog post you will have idea about how to check if customer is logged in or not in Magento 2.

It is always best practice to do not use ObjectManager directly. You can use following code to check user is logged in or not in any class except template files.

You need to use this Magento\Customer\Model\Session::isLoggedIn() method in following way.  First you need to inject the following class in your constructor: /Magento/Customer/Model/Session.

Then in you class you can use following snippet of code anywhere.

By | 2019-07-09T12:11:09+00:00 July 18th, 2016|Magento 2, Programmiing|

Leave A Comment