How to assign a group to user programmatically in magento
Last Modified at 2019-06-25 21:29:27
Sometimes, we need to create an observer to assign a group to user programatically. Because there is no rule available in Magento to change user group as we set the rules for shopping cart and catalog. Although, an option is available in Magento System->Configuration->Customers->Customer Configuration-> Create New Account Option. But if you set a group then all new users will be assigned to it. And in some cases, we need to assign it programmatically.
So here is the simple three lines of code:
$customer = $observer->getEvent()->getCustomer();
$customer->setData('group_id', 3); // or whatever the group id you want to assign
Hope this small tutorial will save your time. Thanks for reading my post.