How to Override name.phtml File for Order, Invoice and Shipment in Magento 2
Overriding name.phtml file can be considered as a frequently required task for a developer who wants customization in the order, invoice, and shipment in Magento 2.
It is widely accepted that modifying the core functionality of default Magento 2 is inappropriate. Thus, it is highly recommended to override the file instead of modifying any core file.
For instance, if a store owner requires to get the value or file in the invoice, shipment, or order view page of the admin panel that the customer added through a custom field or file uploader from an order page.
In such a case, you first have to follow the method to override name.phtml file for order, invoice and shipment in Magento 2 and then you can get values using further code as per your business requirement.
You can override the name.phtml file for the below files:
- For Creditmemo
- sales_order_creditmemo_new.xml
- sales_order_creditmemo_updateqty.xml
- sales_order_creditmemo_view.xml
- For Orders
- sales_order_view.xml
- For Invoice
- sales_order_invoice_new.xml
- sales_order_invoice_updateqty.xml
- sales_order_invoice_view.xml
- For Shipment
- adminhtml_order_shipment_new.xml
- adminhtml_order_shipment_view.xml
Use the below code to override name.phtml file.
Method to Override name.phtml File for Order, Invoice and Shipment in Magento 2
Use the below code in your .xml file located at Vendor/Module/view/adminhtml/layout
1 2 3 4 5 6 7 8 9 10 |
<?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="order_items"> <block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Vendor_Module::items/column/name.phtml" group="column"/> </referenceBlock> </body> </page> |
You can override for any of the files mentioned above.
For example, I’ve override name.phtml file for sales_order_view.xml as shown below:
1 2 3 4 5 6 7 8 9 10 11 12 |
<?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"> <update handle="sales_order_transactions_grid_block"/> <update handle="sales_order_item_price"/> <body> <referenceBlock name="order_items"> <block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Vendor_Module::items/column/name.phtml" group="column"/> </referenceBlock> </body> </page> |
Now you need to create name.phtml at Vendor/Module/view/adminhtml/templates/items/column
That’s all!
If you have any doubts in the above solution, just mention them in the Comments section below.
I’d be glad to help you out.
Feel free to share the post with fellow developers via social media.
You can also refer to the relevant solution to override block, model, and controller in Magento 2 and override a phtml file using a custom module in Magento 2 that I posted earlier.
Thank You.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Enable/Disable Demo Store Notice in Magento 2
How to Set System Configuration Value Using CLI Command in Magento 2
Next