Magento2 I need to override new order email template named order_new.html using custom module & not in theme via app/design.
How can I achieve this?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityMagento2 I need to override new order email template named order_new.html using custom module & not in theme via app/design.
How can I achieve this?
You need to follow below steps in your custom module.
Step 1: Please create email_templates.xml under path Zealousweb/Custom/etc
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="sales_email_order_template" label="New Order" file="custom_order_new.html" type="html" module="Zealousweb_Custom" area="frontend"/>
</config>
Step 2: Please create file custom_order_new.html under path Zealousweb/Custom/view/frontend/email/
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<!--@subject {{trans "Your %store_name order confirmation" store_name=$store.frontend_name}} @-->
<!--@vars {
"var formattedBillingAddress|raw":"Billing Address",
"var order_data.email_customer_note|escape|nl2br":"Email Order Note",
"var order.increment_id":"Order Id",
"layout handle=\"sales_email_order_items\" order=$order area=\"frontend\"":"Order Items Grid",
"var payment_html|raw":"Payment Details",
"var formattedShippingAddress|raw":"Shipping Address",
"var order.shipping_description":"Shipping Description",
"var shipping_msg":"Shipping message",
"var created_at_formatted":"Order Created At (datetime)",
"var store.frontend_name":"Store Frontend Name",
"var store_phone":"Store Phone",
"var store_email":"Store Email",
"var store_hours":"Store Hours",
"var this.getUrl($store,'customer/account/',[_nosid:1])":"Customer Account URL",
"var order_data.is_not_virtual":"Order Type",
"var order":"Order",
"var order_id": "Order DB Id",
"var order_data.customer_name":"Customer Name"
} @-->
{{template config_path="design/email/header_template"}}
<table>
<tr class="email-intro">
<td>
<p class="greeting">{{trans "%customer_name," customer_name=$order_data.customer_name}}</p>
<p>
{{trans "Thank you for your order from %store_name." store_name=$store.frontend_name}}
{{trans "Once your package ships we will send you a tracking number."}}
{{trans 'You can check the status of your order by <a href="%account_url">logging into your account</a>.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}
</p>
<p>
{{trans 'If you have questions about your order, you can email us at <a href="mailto:%store_email">%store_email</a>' store_email=$store_email |raw}}{{depend store_phone}} {{trans 'or call us at <a href="tel:%store_phone">%store_phone</a>' store_phone=$store_phone |raw}}{{/depend}}.
{{depend store_hours}}
{{trans 'Our hours are <span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
{{/depend}}
</p>
</td>
</tr>
<tr class="email-summary">
<td>
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
<p>{{trans 'Placed on <span class="no-link">%created_at</span>' created_at=$created_at_formatted |raw}}</p>
</td>
</tr>
<tr class="email-information">
<td>
{{depend order_data.email_customer_note}}
<table class="message-info">
<tr>
<td>
{{var order_data.email_customer_note|escape|nl2br}}
</td>
</tr>
</table>
{{/depend}}
<table class="order-details">
<tr>
<td class="address-details">
<h3>{{trans "Billing Info"}}</h3>
<p>{{var formattedBillingAddress|raw}}</p>
</td>
{{depend order_data.is_not_virtual}}
<td class="address-details">
<h3>{{trans "Shipping Info"}}</h3>
<p>{{var formattedShippingAddress|raw}}</p>
</td>
{{/depend}}
</tr>
<tr>
<td class="method-info">
<h3>{{trans "Payment Method"}}</h3>
{{var payment_html|raw}}
</td>
{{depend order_data.is_not_virtual}}
<td class="method-info">
<h3>{{trans "Shipping Method"}}</h3>
<p>{{var order.shipping_description}}</p>
{{if shipping_msg}}
<p>{{var shipping_msg}}</p>
{{/if}}
</td>
{{/depend}}
</tr>
</table>
{{layout handle="sales_email_order_items" order_id=$order_id area="frontend"}}
</td>
</tr>
</table>
{{template config_path="design/email/footer_template"}}
Now above overridden template will work. Please check.You can check by adding/modifying any text and check email after that.
Cheers!