Get FirstName in Invoice Email in Magento

Get FirstName in Invoice Email in Magento

September 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Get FirstName in Invoice Email in Magento

Customizing Magento Invoice Emails: Displaying Only the Customer’s First Name

As an e-commerce developer, I often encounter situations where clients want to personalize their store emails by addressing customers using only their first names in invoice messages. By default, Magento includes both the customer’s first and last name in email templates.

Let’s dive into how you can modify the standard Magento 2 invoice template to display only the customer’s first name instead of their full name.

Understanding the Default Template

The default Magento 2 invoice email template file is located at app/code/Magento/Theme/view/frontend/templates/email/invoice_new.html. In this file, you’ll find a line similar to the following:

<p style="font-size:13px;line-height:150%;">
    Hello, {{htmlescape var=$order.getCustomerFirstname()}} {{htmlescape var=$order.getCustomerLastname()}},
</p>

This code snippet addresses the customer using their full name (firstName lastName).

Modifying the Template to Display Only the First Name

To display only the customer’s first name in the invoice email, follow these steps:

  1. Navigate to the app/code/Magento/Theme folder.

  2. Find and open the view/frontend/templates/email/invoice_new.html file.

  3. Replace the line containing the full name with this modified version:

<p style="font-size:13px;line-height:150%;">
    Hello, {{htmlescape var=$order.getCustomerFirstname()}},
</p>

You’ve just removed $order.getCustomerLastname() from the code, which will now display only the customer’s first name.

Using Custom Templates for Better Control

While the above change is straightforward, it’s essential to understand that modifying core files directly can lead to issues during updates. A better approach is to create a custom email template and use it instead of the default one.

To create a custom invoice template:

  1. Go to app/code/Magento/Theme/view/frontend/templates/email and create a new folder named custom.

  2. Inside the custom folder, create your own invoice_new.html file with the modified code.

  3. To use this custom template, update the email configuration in the Magento admin panel:

    • Navigate to Stores > Configuration > Sales > Sales Emails.
    • Set both “New Order” and “Invoice” templates to use the new custom template you created.

Conclusion

In conclusion, modifying the default invoice email template is a simple yet powerful way to enhance the customer experience by addressing them personally using only their first names. By following the steps outlined above, you can achieve this customization easily.

Remember, working with core files directly should be avoided when possible due to update compatibility issues. Creating custom templates provides better control and ensures your modifications remain intact during upgrades.

If you’re looking for more in-depth guidance on Magento email template customization or any other e-commerce development needs, feel free to explore our resources at Laravel Company. We offer comprehensive solutions tailored to help businesses like yours thrive in the digital landscape.

Magento 2 Themes Email Orders

Our network