Magento 2 – Override Order Shipment View Info PHTML in Adminhtml

adminhtmllayoutmagento2overridesphtml

I tried to override phtml template for order_info block in Magento order shipment view layout like this:

app/code/Namespace/Module/view/adminhtml/layout/adminhtml_order_shipment_view.xml

<?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_info">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Namespace_Module::order/view/info.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

app/code/Namespace/Module/view/adminhtml/templates/order/view/info.phtml

<h1> Success </h1>

after i cleared cache and setup:upgrade, nothing changed, it still loads the magento core phtml

Best Answer

Try this code to override template of adminhtml.

Admin > Sales > Orders > View > Shipments > View

  1. app/code/[VendorName]/[ModuleName]/registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    '[VendorName]_[ModuleName]',
    __DIR__
);
  1. app/code/[VendorName]/[ModuleName]/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="[VendorName]_[ModuleName]" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Shipping"/>
        </sequence>
    </module>
</config>
  1. app/code/[VendorName]/[ModuleName]/view/adminhtml/layout/adminhtml_order_shipment_view.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="form">
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="[VendorName]_[ModuleName]::order/view/info.phtml">
                <container name="extra_customer_info"/>
            </block>
        </referenceBlock>
    </body>
</page>
  1. app/code/[VendorName]/[ModuleName]/view/adminhtml/templates/order/view/info.phtml
<h1><?= $block->escapeHtml(__('Success')) ?></h1>