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:
<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>
That’s it.
Also, do share the solution with the Magento Community via social media.
Thank you.