i have created custom customer registration form , how to display customer group in dropdown menu please help me..

  • Dropdown menu where? Commented Aug 9, 2019 at 19:30
  • I want to add dropdown menu in My custom form frontendside @Dominic Xigen Commented Aug 10, 2019 at 3:20

2 Answers 2


Please create module and add below code in Block file.

namespace Vendor\CustomerGroup\Block;

class CustomerGroup extends \Magento\Framework\View\Element\Template
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Customer\Model\ResourceModel\Group\CollectionFactory $groupCollectionFactory,
        array $data = []
    ) {
        $this->groupCollectionFactory = $groupCollectionFactory;
        parent::__construct($context, $data);

     * Retrieve customer group collection
     * @return GroupCollection
    public function getCustomerGroupCollection()
        if (!$this->hasData('customer_group_collection')) {
            $collection = $this->groupCollectionFactory->create();
            $this->setData('customer_group_collection', $collection);

        return $this->getData('customer_group_collection');

And then you can get customer group data in template file

$customerGroupCollection = $block->getCustomerGroupCollection();
foreach($customerGroupCollection as $customerGroup) {
    echo 'ID '.$customerGroup->getId();
    echo 'Code '.$customerGroup->getCode();
    echo 'Tax class Id '.$customerGroup->getTaxClassId();
    echo "<br>";

Hope it will work for you

  • Yes it is helpful there is any way to display only wholesaler, distributor, retailor group onlydisplay? Commented Aug 12, 2019 at 10:15
  • You can add a condition by $customerGroup->getCode() Commented Aug 12, 2019 at 10:30

Please try with below code :

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$groupOptions = $objectManager->get('\Magento\Customer\Model\ResourceModel\Group\Collection')->toOptionArray();
     <?php foreach($groupOptions as $groupOption) { ?>
     <option value="<?php echo $groupOption->getId(); ?>"><?php echo $groupOption->getCode(); ?></optinon>
     <?php } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.