How to add an extra column in Item ordered tab in Magento 2?


enter image description here

Any ideas?


If you want to add a new column at then you have to work on below files:


Create sales_order_view.xml at your module app/code/{Vendor}/{ModuleName}/view/adminhtml/layout

and add a new column using below code

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="order_items">
                <argument name="columns" xsi:type="array">
                    <item name="customcol" xsi:type="string" translate="true">Custom column</item>
            <block class="{Vendor}\{ModuleName}\Block\Adminhtm\Items\Column\Custom" name="column_customcol" 
                   template="{Vendor}_{ModuleName}::items/column/custom.phtml" group="column"/>         
        <referenceBlock name="default_order_items_renderer">
                <argument name="columns" xsi:type="array">
                    <item name="customcol" xsi:type="string" translate="false">col-customcol</item>

Here customcol is a unique identifier for the new column.

BLock class Column.php for showing content.Location app/code/{Vendor}/{ModuleName}/Block/Adminhtm/Items/Column/Custom.php

and Code:

namespace {Vendor}\{ModuleName}\Block\Adminhtm\Items\Column;

class Custom  extends \Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn


Phtml custom.phtml file for this block app/code/{Vendor}/Magento/view/adminhtml/templates/items/column/custom.phtml

and Code is:

// phpcs:disable Magento2.Templates.ThisInTemplate
/* @var $block \Magento\Sales\Block\Adminhtml\Items\Column\Name */
<?php if ($_item = $block->getItem()) : ?>
    <div id="order_item_<?= (int) $_item->getId() ?>_title"
        <?= $block->escapeHtml($_item->getName()) ?>
<?php endif; ?>


Replace {Vendor} with Your module vendor name and {ModuleName} replace Module Name.

  • thank you sir. it's working now – Devidas Aug 21 '19 at 12:32
  • @Devidas please mark the answer as solved if the answer solves your question. – Rendy Eko Prastiyo Aug 21 '19 at 20:16
  • @RendyEkoPrastiyo, thank but you cannot ask the user accept this his/her answer – Amit Bera Aug 22 '19 at 5:35

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.