{"id":1599,"date":"2021-02-23T10:26:15","date_gmt":"2021-02-23T10:26:15","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-all-customer-groups-in-magento-2\/"},"modified":"2025-07-16T17:57:19","modified_gmt":"2025-07-16T12:27:19","slug":"get-all-customer-groups-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-all-customer-groups-in-magento-2\/","title":{"rendered":"How to Get All Customer Groups in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 CMS is the preferred platform to build E-commerce stores owing to its features that address modern business requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One such feature is&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/configure-customer-group-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">customer groups in Magento 2<\/a>&nbsp;that help in targeted customer management, customer-wise marketing efforts, and developing features based on types of customers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are a store owner with a wide variety of products and a large customer base with various customer types, managing customer groups is an essential task, and when you want to implement any functionalities based on the Magento 2 customer groups you need to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/add-customer-group-field-in-magento-2-admin-ui-component-form\/\">add customer group field in Magento 2 admin UI component form<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Customer groups let you categorize the store\u2019s customer base into different groups. Once you have grouped customers, you can create rules, tax classes, and group-specific discounts that pertain to individual customer groups.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The\u00a0Magento 2\u00a0offers the following customer group types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>General<\/li>\n\n\n\n<li>Not Logged in<\/li>\n\n\n\n<li>Retailer<\/li>\n\n\n\n<li>Wholesale<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Besides these, one can&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-customer-group-programmatically-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">create a customer group programmatically in Magento 2<\/a>&nbsp;based on custom business requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While working with the extensions based on customer groups, one often needs to&nbsp;get all customer groups in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, the admin wants to offer different pricing strategies for wholesalers only and cash on delivery option should only be enabled for VIP customer groups.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Or \u201cinstant delivery\u201d is to be offered only to higher customer groups. Or, restrict a payment method for not logged in customer group.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In all such scenarios, one needs to get all customer groups in Magento 2 and use the below solution for the same:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution to get all customer groups in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a&nbsp;<strong>Helper&nbsp;<\/strong>file at&nbsp;<strong>Vendor\/Extension\/Helper<\/strong>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendore\\Extension\\Helper;\n\nuse Magento\\Customer\\Model\\ResourceModel\\Group\\Collection as CustomerGroup;\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\n\nclass Data extends AbstractHelper\n{\n    protected $customerGroup;\n\n    public function __construct(\n        Context $context,\n        CustomerGroup $customerGroup\n    )\n    {\n        $this->customerGroup = $customerGroup;\n        parent::__construct($context);\n    }\n\n    public function getCustomerGroups()\n    {\n        $customerGroups = $this->customerGroup->toOptionArray();\n        return $customerGroups;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use the&nbsp;<strong>getCustomerGroups()&nbsp;<\/strong>of helper file, where you want to get all customer groups.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t forget to share this solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 CMS is the preferred platform to build E-commerce stores owing to its features that address modern business requirements. One such feature is&nbsp;customer groups&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1599","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1599"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1599\/revisions"}],"predecessor-version":[{"id":14480,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1599\/revisions\/14480"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}