{"id":3326,"date":"2022-07-20T13:24:12","date_gmt":"2022-07-20T13:24:12","guid":{"rendered":"https:\/\/www.cynoinfotech.com\/?p=3326"},"modified":"2022-07-20T13:24:12","modified_gmt":"2022-07-20T13:24:12","slug":"how-to-get-current-customer-group-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/","title":{"rendered":"HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2"},"content":{"rendered":"<p>In this blog, we are going to talk about how to get a current customer group id in Magento 2.<\/p>\n<p>The current customer group ID has several developer requirements. If a customer is logged in then how to know which group he belongs to we have created this blog.<\/p>\n<p>see this code:<\/p>\n<pre class=\"lang:default decode:true\">public function __construct(\r\n  \\Magento\\Customer\\Model\\Session $customer,\r\n  \\Magento\\Framework\\App\\Http\\Context $_httpContext\r\n)\r\n{\r\n   $this-&gt;customer = $customer;\r\n   $this-&gt;httpContext = $_httpContext;\r\n}\r\n\r\npublic function  getCurrentCustomerGroupId() {\r\n\r\n$isLoggedIn = $this-&gt;  -&gt;getValue(\\Magento\\Customer\\Model\\Context::CONTEXT_AUTH);\r\n\r\n        if ($isLogin) {\r\n             $currentGroupId = $this-&gt;customer-&gt;getCustomer()-&gt;getGroupId(); \r\n        } else {\r\n            $currentGroupId = 0;\r\n        }\r\nreturn $currentGroupId;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u21d2 <strong>Call phtml file:<br \/>\n<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$_customerGroupsCollection = $block-&gt; getCurrentCustomerGroupId();\r\n $_customerGroupsCollection-&gt;getData();\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u21d2 <strong>Using Object Manager :<\/strong><\/p>\n<pre class=\"lang:default decode:true\">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\r\n$_customerSession = $objectManager-&gt;create('Magento\\Customer\\Model\\Session');\r\n\r\nif ($_customerSession -&gt;isLoggedIn()) {\r\n\r\n\/\/Get current group ID:-\r\n\r\n     $_customerGroupId = $_customerSession-&gt;getCustomer()-&gt;getGroupId();\r\n     $_groupCollection = $objectManager-&gt;create('\\Magento\\Customer\\Model\\Group')-&gt;load($_customerGroupId);\r\n\t\t\t\t\r\n   $_groupCollection-&gt;getData();\r\n}\r\n\r\n<\/pre>\n<p>I hope you have understood this blog. If you have any problems then tell me below comment section<\/p>\n<p>&nbsp;<\/p>\n<p>Thank You!!..<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we are going to talk about how to get a current customer group id in Magento 2. The current customer group ID has several developer requirements. If a customer is logged in then how to know which group he belongs to we have created this blog. see this code: public function __construct( [&hellip;]<\/p>\n","protected":false},"author":670,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3326","post","type-post","status-publish","format-standard","hentry","category-magento-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2 - cynoinfotech<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/\"},\"author\":{\"name\":\"Arjun Makadiya\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24\"},\"headline\":\"HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2\",\"datePublished\":\"2022-07-20T13:24:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/\"},\"wordCount\":89,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#organization\"},\"articleSection\":[\"Magento blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/\",\"url\":\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/\",\"name\":\"HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2 - cynoinfotech\",\"isPartOf\":{\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#website\"},\"datePublished\":\"2022-07-20T13:24:12+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cynoinfotech.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#website\",\"url\":\"https:\/\/cynoinfotech.com\/blog\/\",\"name\":\"cynoinfotech\",\"description\":\"web design &amp; development\",\"publisher\":{\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cynoinfotech.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#organization\",\"name\":\"Cynoinfotech\",\"url\":\"https:\/\/cynoinfotech.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png\",\"contentUrl\":\"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png\",\"width\":240,\"height\":70,\"caption\":\"Cynoinfotech\"},\"image\":{\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/cynoinfotech\/\",\"https:\/\/x.com\/cynoinfotech\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24\",\"name\":\"Arjun Makadiya\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"caption\":\"Arjun Makadiya\"},\"description\":\"Arjun Makadiya is a Junior Magento Developer at Cynoifotech. He is passionate about technology. Apart from work he likes to play cricket.\",\"url\":\"https:\/\/cynoinfotech.com\/blog\/author\/arjun-makadiya\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2 - cynoinfotech","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/"},"author":{"name":"Arjun Makadiya","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24"},"headline":"HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2","datePublished":"2022-07-20T13:24:12+00:00","mainEntityOfPage":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/"},"wordCount":89,"commentCount":0,"publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"articleSection":["Magento blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/","url":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/","name":"HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2 - cynoinfotech","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/#website"},"datePublished":"2022-07-20T13:24:12+00:00","breadcrumb":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-current-customer-group-id-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cynoinfotech.com\/blog\/"},{"@type":"ListItem","position":2,"name":"HOW TO GET CURRENT CUSTOMER GROUP ID IN MAGENTO 2"}]},{"@type":"WebSite","@id":"https:\/\/cynoinfotech.com\/blog\/#website","url":"https:\/\/cynoinfotech.com\/blog\/","name":"cynoinfotech","description":"web design &amp; development","publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cynoinfotech.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cynoinfotech.com\/blog\/#organization","name":"Cynoinfotech","url":"https:\/\/cynoinfotech.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png","contentUrl":"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png","width":240,"height":70,"caption":"Cynoinfotech"},"image":{"@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cynoinfotech\/","https:\/\/x.com\/cynoinfotech"]},{"@type":"Person","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24","name":"Arjun Makadiya","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","caption":"Arjun Makadiya"},"description":"Arjun Makadiya is a Junior Magento Developer at Cynoifotech. He is passionate about technology. Apart from work he likes to play cricket.","url":"https:\/\/cynoinfotech.com\/blog\/author\/arjun-makadiya\/"}]}},"_links":{"self":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/users\/670"}],"replies":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=3326"}],"version-history":[{"count":1,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3326\/revisions"}],"predecessor-version":[{"id":3327,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3326\/revisions\/3327"}],"wp:attachment":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=3326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=3326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=3326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}