skip to Main Content

How we can add column to Sales order history content into customer account.

What are methods for add a column to sales_order_history page without editing view/frontend/templates/order/history.phtml?

enter image description here

3

Answers


  1. You don’t need to touch view/frontend/templates/order/history.phtml template file to add aditional column into customer sales order history page.

    copy layout view/frontend/layout/sales_order_history.xml to your theme and add addtional column header to sales.order.history.extra.column.header block and render column data using sales.order.history.extra.container block.

    You have all set now.

    Login or Signup to reply.
  2. <?xml version="1.0"?>
    <!--
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <body>
            <!-- This will add additional column header to order list -->
            <referenceBlock name="sales.order.history.extra.column.header">
                <block class="MagentoFrameworkViewElementTemplate" name="your.additional.column.header" template="Namespace_Module::columnheader.phtml"/>
            </referenceBlock>
    
            <!-- You can access current order using $this->getOrder() inside the template ">
            <referenceBlock name="sales.order.history.extra.container">
                <block class="MagentoFrameworkViewElementTemplate" name="your.additional.column.data" template="Namespace_Module::columndata.phtml"/>
            </referenceBlock>
        </body>
    </page>
    
    Login or Signup to reply.
  3. I have an easier and shorter solution(date column in the example):

    1- Create in your theme/extension into layout folder-> sales_order_history.xml and copy:

     <?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="sales.order.history.extra.container" template="Magento_Sales::order/date/data.phtml"/>
        </body>
    </page>
    

    2- Create the template for the data in templates/date/data.phtml and copy:

    <?php
    /* @var $block MagentoSalesBlockOrderHistoryContainer */
    ?>
    <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date">
        <?= $block->escapeHtml($block->getOrder()->getCreatedAt()) ?></td>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search