{"id":346,"date":"2016-02-11T15:20:20","date_gmt":"2016-02-11T09:50:20","guid":{"rendered":"http:\/\/www.magewallet.com\/?p=346"},"modified":"2020-03-13T16:09:15","modified_gmt":"2020-03-13T10:39:15","slug":"magento-2-get-current-logged-customer","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-get-current-logged-customer\/","title":{"rendered":"Magento 2 &#8211; Get current logged in customer details"},"content":{"rendered":"<p>In this blog post, we will see how to retrieve currently logged in customer details in Magento 2.<\/p>\n<p>We can retrieve the currently logged in customer details using an instance of <em>\\Magento\\Customer\\Model\\Session<\/em> model through constructor. After initialization of model instant, we need to store instantiated object into protected variable like <em>$customerSession<\/em>. Session model contains so many methods related to customer and we can use this methods to retrieve customers details. Below are some of the methods.<\/p>\n<ol>\n<li>isLoggedIn()<\/li>\n<li>getCustomerId()<\/li>\n<li>getCustomerGroupId()<\/li>\n<li>getCustomer()<\/li>\n<li>getCustomerData()<\/li>\n<\/ol>\n<div style=\"display: block; float: left; width: 100%; padding: 30px 0; background: black; border-radius: 5px; margin: 0 0 25px 0;\">\n<p style=\"text-align: center;\"><a style=\"color: #fff; font-size: 28px; font-weight: 600;\" href=\"https:\/\/www.hiddentechies.com\/blog\/magento\/free-magento-2-3-3-themes\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Free Magento 2.3.3 Themes for 2020<\/a><\/p>\n<\/div>\n<p>We can call this methods as shown below.<\/p>\n<pre class=\"lang:default decode:true \">if($customerSession-&gt;isLoggedIn()) {  \r\n  customerSession-&gt;getCustomerId();\r\n  customerSession-&gt;getCustomerGroupId();\r\n  customerSession-&gt;getCustomer();\r\n  customerSession-&gt;getCustomerData();\r\n}<\/pre>\n<p>You can use above code snippet to get current logged in customer details. That&#8217;s it. Enjoy!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post, we will see how to retrieve currently logged in customer details in Magento 2. We can retrieve the currently logged in customer details using an instance of \\Magento\\Customer\\Model\\Session model through constructor. After initialization of model instant, we need to store instantiated object into protected variable like $customerSession. Session model contains so&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-get-current-logged-customer\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":4896,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[80,10],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/346"}],"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=346"}],"version-history":[{"count":4,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions"}],"predecessor-version":[{"id":10499,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions\/10499"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/4896"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}