Magento – how to modify order/items.phtml file in magento 2

magento2

  1. I copied file from Following Location:

vendor\magento\module_sales\view\frontend\templates\order\items.phtml
and paste in

app\code\vendorname\Madule\view\frontend\templates\order\items.phtml

2.Copied sales_order_view.xml from

vendor\magento\module_sales\view\frontend\layout and paste it in custom module

at

app\code\vendorname\Madule\view\frontend\layout

did changes in template path

<block class="Magento\Sales\Block\Order\Items" name="order_items" template="vendorname_Madule::order/items.phtml">

still it show vendor files

Best Answer

If you want to manage this from a custom module then

Create below layout files at

  1. app/code/{Vendorname}/{Modulename}/view/frontend/layout/sales_order_view.xml

Code

<?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>
        <referenceContainer name="order_items">
            <arguments>
                <argument name="template" xsi:type="string">{Vendorname}_{Modulename}::order/items.phtml</argument>
            </arguments>
        </referenceContainer>
    </body>
</page>
  1. app/code/{Vendorname}/{Modulename}/view/frontend/layout/sales_guest_print.xml

Code

<?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>
        <referenceContainer name="order_items">
            <arguments>
                <argument name="template" xsi:type="string">{Vendorname}_{Modulename}::order/items.phtml</argument>
            </arguments>
        </referenceContainer>
    </body>
</page>
  1. app/code/{Vendorname}/{Modulename}/view/frontend/layout/sales_guest_view.xml

Code

<?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>
        <referenceContainer name="order_items">
            <arguments>
                <argument name="template" xsi:type="string">{Vendorname}_{Modulename}::order/items.phtml</argument>
            </arguments>
        </referenceContainer>
    </body>
</page>
  1. app/code/{Vendorname}/{Modulename}/view/frontend/layout/sales_order_print.xml

Code

<?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>
        <referenceContainer name="order_items">
            <arguments>
                <argument name="template" xsi:type="string">{Vendorname}_{Modulename}::order/items.phtml</argument>
            </arguments>
        </referenceContainer>
    </body>
</page>

You Module should be depend on Magento_Sales modules,So add Magento_Sales as depends module of your module using module.xml(app/code/{Vendorname}/{Modulename}/etc/)

By Theme

If you using any custom theme then just copy

vendor\magento\module_sales\view\frontend\templates\order\items.phtml

to

app/design/frontend/{ThemeVendorname}/{ThemeName}/Magento_Sales/templates/order/items.phtml

And

vendor\magento\module_sales\view\frontend\layout\sales_order_view.xml

to

app/design/frontend/{ThemeVendorname}/{ThemeName}/Magento_Sales/layout/sales_order_view.xml