How to Add Column to Customer Sales Order History Page in Magento 2
Magento 2 offers a “My Account” section for the customers to check their details like account details, order and payment details, shipment, taxes, etc.
It is always a good practice for online stores to deliver maximum information to the customers about their orders, payments, shipping, etc.
With online shopping, until the customers do not get their items in hand, the urge to know about their order increases. The “My Account” section in Magento 2 store answers such customers’ questions.
Now, every business is different and has unique requirements. So, if you need to display any additional order details, you can do so with the below method to add column to customer sales order history page in Magento 2.
And, if you need to display the order history in the admin panel, you can install Meetanshi’s Magento 2 Order History extension to track any orders related to a product or customer.
Here’s an example where the “Customer Note” column is added and the sales order history page is customized for the same:
Magento 2 Add Column to Customer Sales Order History Page
- Create a file at path app/code/Vendor/Module/view/frontend/layout/sales_order_history.xml
123456789101112<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 name="vendor.additional.column.header" template="Vendor_Module::extraColumn-header.phtml"/></referenceBlock><!-- You can access current order using $this->getOrder() inside the template "--><referenceBlock name="sales.order.history.extra.container"><block name="vendor.additional.column.data" template="Vendor_Module::extraColumn.phtml"/></referenceBlock></body> - Create template file at path app/code/Vendor/Module/view/frontend/templates/extraColumn-header.phtml
123456<?php/* @var $block \Magento\Sales\Block\Order\History\Container */?><th data-th="<?= $block->escapeHtml(__('Customer Note')) ?>" class="col"><?= $block->escapeHtml("Customer Note") ?></th> - Create template file at path app/code/Vendor/Module/view/frontend/templates/extraColumn.phtml
1234567<?php/* @var $block \Magento\Sales\Block\Order\History\Container */?><td data-th="<?= $block->escapeHtml(__('Customer Note')) ?>" class="col"><?= $block->escapeHtml($block->getOrder()->getCustomerNote()) ?></td>
That’s it.
By following the above method, you can easily add column to sales order history page (FO) in Magento 2. Any doubts in the solution can be mentioned in the Comments section below. I’d be happy to help.
Also, do share the solution with fellow Magento developers via social media.
Thank you.
Chandresh Chauhan
He has been with Meetanshi for more than three years now as a certified Magento developer. A silent guy whom you can always find solving clients' issues, is an avid reader too.
2 Comments
It works thankyou!
Hello Muiz,
You’re most welcome.
We’re glad to know that the above solution helped you
Thank you