The default email Order Confirmation Template includes the Order Items Grid variable.

I need to add custom information to the first column. By default, the first column in the grid looks contains just the item name and item SKU. I need to call my own function for each item and generate a code that needs to be added right after item SKU.

Where do I do it programmatically?


Here is the solution I have customized sales_order_invoice area so you can customized any area which you want only you have to follow the steps only your are will be different.

files are below in which you need to customize:-



<?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">
       <referenceBlock name="invoice_items">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Namespace_ModuleName::order/invoice/items.phtml</argument>


<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Block\Order\Invoice\Items" type="Namespace\ModuleName\Block\Order\Invoice\Items" />

Items.php :- You block file you will create function here to access in your phtml file.


namespace Namespace\ModuleName\Block\Order\Invoice;

class Items extends \Magento\Sales\Block\Order\Invoice\Items

    private $orderItem;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Sales\Model\Order\Item $orderItem,
        array $data = []
    ) {
        parent::__construct($context, $registry, $data);
        $this->orderItem = $orderItem;

    public function YourCustomFunction()
      //You code will be here


Items.phtml :- here is the file where you will add your custom information

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

// @codingStandardsIgnoreFile

<?php $_order = $block->getOrder() ?>
<div class="actions-toolbar">
    <a href="<?= /* @escapeNotVerified */ $block->getPrintAllInvoicesUrl($_order) ?>"
       class="action print">
        <span><?= /* @escapeNotVerified */ __('Print All Invoices') ?></span>
<?php foreach ($_order->getInvoiceCollection() as $_invoice): ?>
<div class="order-title">
    <strong><?= /* @escapeNotVerified */ __('Invoice #') ?><?= /* @escapeNotVerified */ $_invoice->getIncrementId() ?></strong>
    <a href="<?= /* @escapeNotVerified */ $block->getPrintInvoiceUrl($_invoice) ?>"
       class="action print">
        <span><?= /* @escapeNotVerified */ __('Print Invoice') ?></span>
<div class="table-wrapper table-order-items invoice">
    <table class="data table table-order-items invoice" id="my-invoice-table-<?= /* @escapeNotVerified */ $_invoice->getId() ?>">
        <caption class="table-caption"><?= /* @escapeNotVerified */ __('Items Invoiced') ?></caption>
                <th class="col name"><?= /* @escapeNotVerified */ __('Product Name') ?></th>
                <th class="col sku"><?= /* @escapeNotVerified */ __('SKU') ?></th>
                <th class="col price"><?= /* @escapeNotVerified */ __('Price') ?></th>
                <th class="col qty"><?= /* @escapeNotVerified */ __('Qty Invoiced') ?></th>
                <th class="col subtotal"><?= /* @escapeNotVerified */ __('Subtotal') ?></th>
        <?php $_items = $_invoice->getAllItems(); ?>
        <?php $_count = count($_items) ?>
        <?php foreach ($_items as $_item): ?>
        <?php if ($_item->getOrderItem()->getParentItem()) {
} ?>
            <?= $block->getItemHtml($_item) ?>
        <?php endforeach; ?>
            <?= $block->getInvoiceTotalsHtml($_invoice) ?>
<?= $block->getInvoiceCommentsHtml($_invoice) ?>
<?php endforeach; ?>

I hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.