We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
How To Get All Customer Groups
Would you like to get all customer groups that you have in your store? Let's see together how you can easily do that!
In our example we will get all customer groups in an array with key the customer id and value the group's label and as collection, by calling the corresponding functions getCustomerGroupsArray() and getCustomerGroupsCollection() from the helper class.
The result by calling the function getCustomerGroupsArray()
array(4) { [0]=> array(2) { ["value"]=> string(1) "0" ["label"]=> string(13) "NOT LOGGED IN" } [1]=> array(2) { ["value"]=> string(1) "1" ["label"]=> string(7) "General" } [2]=> array(2) { ["value"]=> string(1) "2" ["label"]=> string(9) "Wholesale" } [3]=> array(2) { ["value"]=> string(1) "3" ["label"]=> string(8) "Retailer" } }
The result by calling the function getCustomerGroupsCollection() and getData() of every item.
array(3) { ["customer_group_id"]=> string(1) "0" ["customer_group_code"]=> string(13) "NOT LOGGED IN" ["tax_class_id"]=> string(1) "3" } array(3) { ["customer_group_id"]=> string(1) "1" ["customer_group_code"]=> string(7) "General" ["tax_class_id"]=> string(1) "3" } array(3) { ["customer_group_id"]=> string(1) "2" ["customer_group_code"]=> string(9) "Wholesale" ["tax_class_id"]=> string(1) "3" } array(3) { ["customer_group_id"]=> string(1) "3" ["customer_group_code"]=> string(8) "Retailer" ["tax_class_id"]=> string(1) "3" }
The full example as extension can be found here.
Feel free to share this post and ask your questions in the comments below.
Till next time!