I have create new custom attribute on Sales_order table name "QR_Code". How to insert this field into my new order email template?
Thanks kllee
I have create new custom attribute on Sales_order table name "QR_Code". How to insert this field into my new order email template?
Thanks kllee
Please Orverride the following file
/var/www/html/app/code/core/Mage/Sales/Model/order.php
and and your custom variable value here near by 1336 line number.
$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml,
'custom_var' => 'custom_value'
));
After this add this variable in your new_order template.
app\locale\en_US\template\email\sales\order_new_guest.html
and add like this {{var custom_var}}
Happy Coding. :)
To send extra field in order email you need to do the following,
Over ride the email template file in custom extension like this.
app\code\Vendor\Extension\view\frontend\layout\sales_email_order_items.xml
Add following code in above file.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="items">
<action method="setTemplate">
<argument name="template" xsi:type="string">Vendor_Extension::email/items.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Create a new template file items.phtml
in your template folder as this.
app\code\Vendor\Extension\view\frontend\templates\email\items.phtml
<?php $_order = $block->getOrder() ?>
<h3><?= $_order->getYOURFIELD(); ?></h3>
<?php if ($_order): ?>
<?php $_items = $_order->getAllItems(); ?>
<table class="email-items">
<thead>
<tr>
<th class="item-info">
<?= /* @escapeNotVerified */ __('Items'); ?>
</th>
<th class="item-qty">
<?= /* @escapeNotVerified */ __('Qty'); ?>
</th>
<th class="item-price">
<?= /* @escapeNotVerified */ __('Price'); ?>
</th>
</tr>
</thead>
<?php foreach ($_items as $_item): ?>
<?php
if ($_item->getParentItem()) {
continue;
}
?>
<tbody>
<?= $block->getItemHtml($_item) ?>
</tbody>
<?php endforeach; ?>
<tfoot class="order-totals">
<?= $block->getChildHtml('order_totals') ?>
</tfoot>
</table>
<?php if ($this->helper('Magento\GiftMessage\Helper\Message')->isMessagesAllowed('order', $_order, $_order->getStore()) && $_order->getGiftMessageId()): ?>
<?php $_giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessage($_order->getGiftMessageId()); ?>
<?php if ($_giftMessage): ?>
<br />
<table class="message-gift">
<tr>
<td>
<h3><?= /* @escapeNotVerified */ __('Gift Message for this Order') ?></h3>
<strong><?= /* @escapeNotVerified */ __('From:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
<br /><strong><?= /* @escapeNotVerified */ __('To:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
<br /><strong><?= /* @escapeNotVerified */ __('Message:'); ?></strong>
<br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
</td>
</tr>
</table>
<?php endif; ?>
<?php endif; ?>
You can echo your custom attribute like this way i was call on switch condition, you can use according to your requirements.
<?php echo $_product->getAttributeText('brand'); ?>
OR
<?php
$brandname = $_product->getAttributeText('brand');
if (trim($brandname)) {
echo "" .$this->htmlEscape($brandname);
}
?>