{"id":2850,"date":"2016-01-15T15:32:00","date_gmt":"2016-01-15T10:02:00","guid":{"rendered":"http:\/\/www.magewallet.com\/?p=300"},"modified":"2020-03-13T16:09:25","modified_gmt":"2020-03-13T10:39:25","slug":"how-to-check-if-customer-is-logged-in-or-not-in-magento-2","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/how-to-check-if-customer-is-logged-in-or-not-in-magento-2\/","title":{"rendered":"How to check if customer is logged in or not in Magento 2?"},"content":{"rendered":"<p>As we know, there are so many situation where we require to check whether customer is currently logged in or not. In this blog post you will learn about how to check customer is logged in or not in Magento 2. In order to check this situation you can use below code snippet.<\/p>\n<pre class=\"lang:default decode:true \">\/** @var \\Magento\\Framework\\App\\ObjectManager $om *\/\r\n$om = \\Magento\\Framework\\App\\ObjectManager::getInstance();\r\n\/** @var \\Magento\\Framework\\App\\Http\\Context $context *\/\r\n$context = $om-&gt;get('Magento\\Framework\\App\\Http\\Context');\r\n\/** @var bool $isLoggedIn *\/\r\n$isLoggedIn = $context-&gt;getValue(\\Magento\\Customer\\Model\\Context::CONTEXT_AUTH);<\/pre>\n<p>Once you got the result in $isLoggedIn variable, you can check condition as per below.<\/p>\n<pre class=\"lang:default decode:true \">if($isLoggedIn){\r\n\r\n\/\/ If customer is logged in\r\n\/\/ Some code snippet here\r\n\r\n}<\/pre>\n<p>You can use above code snippet. That&#8217;s it. Enjoy!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we know, there are so many situation where we require to check whether customer is currently logged in or not. In this blog post you will learn about how to check customer is logged in or not in Magento 2. In order to check this situation you can use below code snippet. \/** @var&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/how-to-check-if-customer-is-logged-in-or-not-in-magento-2\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":4895,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[197,10],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/2850"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=2850"}],"version-history":[{"count":2,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/2850\/revisions"}],"predecessor-version":[{"id":10497,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/2850\/revisions\/10497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/4895"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=2850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=2850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=2850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}