Home » Magento, Magento 24 January 2017

Magento 2: Get Customer Groups

This article shows how to get all customer groups name and id in Magento 2.

I will be showing an example in a Block class. You can write the code in other class (Helper/Model) as well.

Both ways (Dependency Injection & Object Manager way) are shown below.

Using Dependency Injection (DI)

Here is the code that you need to write in your Block class.

Using Object Manager

The output array while calling getCustomerGroups() method will be something like this:

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • magento

  • Vikram

    Gives Below Exception

    Fatal error: Uncaught TypeError: Argument 2 passed to MagentoCustomerBlockFormRegister::__construct() must be an instance of MagentoDirectoryHelperData