Skip to content

How can I change an email template variable to show the Customer Group Name instead of the ID number

I was shown how to create an observer to grab the customer groupID and create a variable that can be added to my email template like this… 

_order = $order;
}

public function execute(Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$customerGroupId = $order->getCustomerGroupId();

// You can do additional processing with the customer group if needed.

$order->setData(‘customer_group_id’, $customerGroupId);
}
}
And in my email template, I can then include {{var order.customer_group_id}} to display the customer group ID.

I would like to know I can make the Variable show the customer group NAME instead of the ID number so my employees don’t all need to remember what every number means.  So for example, if customerGroupId = 0 then it would say Not Logged In, if customerGroupId = 1, then it would say General. 

I don’t know php very well and have just started using Magento so if anyone can help, I’d really appreciate it.

Thanks.