I'm very new to Magento.

I'm using Magento 2.4.6 and I want to add Customer Group to the New Order email template. We need some way to know what customer group belongs to because we do different things whether the order is from a general, wholesale, or fundraising customer. I don't know if there is a variable that can just be dropped into the email template or not so we can see it when we print the order.

1 Answer 1


In Magento 2.4.6, you can indeed customize the New Order email template to include the customer group. However, by default, Magento doesn't provide a variable for the customer group directly in the New Order email template. You'll need to create a custom module to achieve this.

Here's a general outline of the steps you would take:

1. Create a custom module: If you haven't already, you'll need to create a custom module in Magento to handle this customization. You can use the built-in module creator or create one manually.

2. Observer: Create an observer that listens to the event dispatched when an order is placed.

3. Retrieve Customer Group: In your observer, you'll retrieve the customer group associated with the order.

4. Pass Data to Email Template: Once you have the customer group, you'll need to pass this data to the email template. You can do this by adding a new variable to the email template.

5. Modify Email Template: Finally, you'll modify the New Order email template to include the customer group variable.

Here's a brief example of how your observer might look:


namespace Vendor\Module\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class AddCustomerGroupToOrderEmail implements ObserverInterface
    protected $_order;

    public function __construct(
        \Magento\Sales\Model\Order $order
    ) {
        $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 your email template, you can then include {{var order.customer_group_id}} to display the customer group ID.

Remember to replace Vendor\Module with the actual namespace of your module. This is a simplified example, and you may need to adjust it based on your specific requirements and coding standards. Additionally, don't forget to properly test your customizations in a development environment before deploying to production.

  • This worked perfectly. If I wanted to use the Group Name as the variable instead of the Group ID, what would I replace or add to the code above? Or better yet, how can I see a list of what the variables on a page are? I'm guessing it would be something like $customerGroupName = $order->getCustomerGroupName();
    – Pete
    Commented May 6 at 17:30
  • Can you tell me how to add the required code to say something like if $customerGroupId = 1, echo Not Logged In? That way my people don't have to remember what the group numbers mean and can see the name of the actual group.
    – Pete
    Commented May 22 at 21:19

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.