I want to add a 'unit price' tab and actual price of the products like this in New Order Email template.. I'm using 'Magento 2.4.6' enter image description here
I need a proper code that i can implement in files with the help of file path as well, Thank You
we can add column into order email template by following way
1.app/design/frontend/[themeparent]/[themename]/Magento_Sales/templates/email/items/order/default.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// phpcs:disable Magento2.Templates.ThisInTemplate
// phpcs:disable Magento2.Files.LineLength, Generic.Files.LineLength
/** @var $block \Magento\Sales\Block\Order\Email\Items\DefaultItems */
/** @var $_item \Magento\Sales\Model\Order\Item */
/** @var \Magento\Framework\Escaper $escaper */
$_item = $block->getItem();
$_order = $_item->getOrder();
?>
<tr>
<td class="item-info<?= ($block->getItemOptions() ? ' has-extra' : '') ?>">
<p class="product-name"><?= $escaper->escapeHtml($_item->getName()) ?></p>
<p class="sku"><?= $escaper->escapeHtml(__('SKU')) ?>: <?= $escaper->escapeHtml($block->getSku($_item)) ?></p>
<?php if ($block->getItemOptions()) : ?>
<dl class="item-options">
<?php foreach ($block->getItemOptions() as $option) : ?>
<dt><strong><em><?= $escaper->escapeHtml($option['label']) ?></em></strong></dt>
<dd>
<?= /* @noEscape */ nl2br($option['value']) ?>
</dd>
<?php endforeach; ?>
</dl>
<?php endif; ?>
<?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?>
<?php if ($addInfoBlock) : ?>
<?= $addInfoBlock->setItem($_item)->toHtml() ?>
<?php endif; ?>
<?= $escaper->escapeHtml($_item->getDescription()) ?>
</td>
<td class="item-unitprice">
<?= $escaper->escapeHtml($_item->getPrice()) ?>
</td>
<td class="item-qty"><?= (float) $_item->getQtyOrdered() ?></td>
<td class="item-price">
<?= /* @noEscape */ $block->getItemPrice($_item) ?>
</td>
</tr>
<?php if (
$_item->getGiftMessageId()
&& $_giftMessage = $this->helper(\Magento\GiftMessage\Helper\Message::class)
->getGiftMessage($_item->getGiftMessageId())
) : ?>
<tr>
<td colspan="3" class="item-extra">
<table class="message-gift">
<tr>
<td>
<h3><?= $escaper->escapeHtml(__('Gift Message')) ?></h3>
<strong><?= $escaper->escapeHtml(__('From:')) ?></strong> <?= $escaper->escapeHtml($_giftMessage->getSender()) ?>
<br /><strong><?= $escaper->escapeHtml(__('To:')) ?></strong> <?= $escaper->escapeHtml($_giftMessage->getRecipient()) ?>
<br /><strong><?= $escaper->escapeHtml(__('Message:')) ?></strong>
<br /><?= $escaper->escapeHtml($_giftMessage->getMessage()) ?>
</td>
</tr>
</table>
</td>
</tr>
<?php endif; ?>
app/design/frontend/[themeparent]/[themename]/Magento_Sales/templates/email/items.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** @var $block \Magento\Sales\Block\Order\Email\Items */
?>
<?php $_order = $block->getOrder() ?>
<?php if ($_order) : ?>
<?php $_items = $_order->getAllItems(); ?>
<table class="email-items">
<thead>
<tr>
<th class="item-info">
<?= $block->escapeHtml(__('Items')) ?>
</th>
<th class="item-unitprice">
<?= $block->escapeHtml(__('Unit Price')) ?>
</th>
<th class="item-qty">
<?= $block->escapeHtml(__('Qty')) ?>
</th>
<th class="item-price">
<?= $block->escapeHtml(__('Price')) ?>
</th>
</tr>
</thead>
<?php foreach ($_items as $_item) : ?>
<?php if (!$_item->getParentItem()) : ?>
<tbody>
<?= $block->getItemHtml($_item) ?>
</tbody>
<?php endif; ?>
<?php endforeach; ?>
<tfoot class="order-totals">
<?= $block->getChildHtml('order_totals') ?>
</tfoot>
</table>
<?php if ($this->helper(\Magento\GiftMessage\Helper\Message::class)
->isMessagesAllowed('order', $_order, $_order->getStore())
&& $_order->getGiftMessageId()
) : ?>
<?php $_giftMessage = $this->helper(\Magento\GiftMessage\Helper\Message::class)
->getGiftMessage($_order->getGiftMessageId()); ?>
<?php if ($_giftMessage) : ?>
<br />
<table class="message-gift">
<tr>
<td>
<h3><?= $block->escapeHtml(__('Gift Message for this Order')) ?></h3>
<strong><?= $block->escapeHtml(__('From:')) ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
<br /><strong><?= $block->escapeHtml(__('To:')) ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
<br /><strong><?= $block->escapeHtml(__('Message:')) ?></strong>
<br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
</td>
</tr>
</table>
<?php endif; ?>
<?php endif; ?>