How to Add Customer Group Field in Magento 2 Admin UI Component Form
The post offers a solution to add customer group field in Magento 2 admin UI component form.
Use the below solution when you want to implement any functionalities based on the Magento 2 customer groups.
For instance, the Magento 2 store admin wants to offer different pricing strategies for wholesalers only and cash on delivery option should only be enabled for VIP customer groups.
Or “instant delivery” is to be offered only to higher customer groups. Or, restrict a payment method for not logged in customer group.
To configure such rules in the admin UI, you will need to add the customer group field which can be done using the below solution:
Method to Add Customer Group Field in Magento 2 Admin UI Component Form:
1 2 3 4 5 6 7 8 9 10 11 12 |
<field name="coustomer_group" sortOrder="40" formElement="multiselect"> <settings> <label translate="true">Customer Group</label> </settings> <formElements> <multiselect> <settings> <options class="Magento\Customer\Model\Customer\Source\GroupSourceInterface"/> </settings> </multiselect> </formElements> </field> |
Any doubts? Do mention them in the Comments section below. I’d be happy to help you out.
Also, do share the solution with the Magento Community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
I need to add ALL Customer group label to customer _group_id field in sales_rule_form.xml and the value will be stored in sales_customer_group table and not customer_group table. kindly guide
Hey Sandhya,
In sales_rule_form.xml already customer group id’s exist by default,
and for saving value to different table you need to find event or rule saving controller for sales rule form
and than you can create save logic there.