When customizing email templates in Magento 2, it's common to include relevant information like the billing country_id.

In this blog post, we will explore how to add the billing country_id from the sales_order_address table directly to the order email template.

This will allow customers to have a better understanding of the order's billing address country.

Let's get started.

Step 1: Locate the email template file

The first step is to locate the email template file where you wish to add the billing country_id.

This file is typically located in the app/design/frontend/[Vendor]/[Theme]/Magento_Sales/templates/email/ directory.

Look for the template file related to the order email, such as order_new.html.

Step 2: Add the country_id variable

Open the email template file using a text editor and locate the section where you want to display the billing country_id. In this case, we want to add it to the billing address section. Add the following code snippet

<p><b>Country:</b> {{var order.getBillingAddress().getCountryId()}}</p>

This code retrieves the country_id value from the sales_order_address table using the getBillingAddress() method and getCountryId() function.

Step 3: Save and test the template

Save the changes to the email template file and navigate to the Magento admin panel.

Place a test order and check the order confirmation email.

You should now see the billing country_id displayed in the billing address section.


By following these simple steps, you can easily add the billing country_id to the order email template in Magento 2.4.5.

This customization will provide customers with a clearer understanding of the order's billing address country.

Feel free to explore further customization options to enhance the email template to meet your specific business needs.

Remember to update the template file in your custom theme, as modifying core files directly is not recommended.

Customizing email templates allows you to personalize the communication with your customers and provide them with a better shopping experience.