How to Override name.phtml File for Order, Invoice and Shipment in Magento 2

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

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:

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.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

4.9
(based on 9 Reviews)

Ronak is a Magento Developer at Meetanshi. He loves playing cricket. Apart from the work, he is an enthusiastic person who loves learning new skills.

Leave a reply:

Your email address will not be published.