Magento 2: How to Add another block in sales/invoice page.
Solution
First,you need to create custom module:
Via custom module
If you donot want to work at direct vendor folder then you need create a custom module
This module should consist of below files:
app/code/app/code/{vendorname}/{Company}/registration.php
app/code/{vendorname}/{Company}/composer.json
app/code/{vendorname}/{Company}/etc/module.xml
then Create a layout file sales_order_invoice_view.xml
at app/code/{vendorname}/{Company}/view/adminhtml/layout
On thissales_order_invoice_view.xml
add below code for change the template via layout for order_info
and Also add a child block of this block which you want.
<?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"
label="Email Order Items List" design_abstraction="custom">
<body>
<referenceBlock name="order_info">
<arguments>
<argument name="template" xsi:type="string">{vendorname}_{Company}::sales/invoice/info.phtml</argument>
</arguments>
<!-- add Block -->
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="custom.blockforinvoice" as="custom.blockforinvoice" template="vendorname}_{Company}::sales/invoice/info.phtml" />
</referenceBlock>
</page>
Now new template phtml is located at app/code/{vendorname}/{Company}/view/adminhtml/templates/sales/invoice/info.phtml
.
And then copy the code of
vendor/magento/module-sales/view/adminhtml/templates/order/view/info.phtml
and paste on new info.phtml
.
After, you need to call your custom block in new info.phtml by add this code
<?php $block->getChildHtml('custom.blockforinvoice') ?>
after <?php endif; ?>
of shipping information
After this your should do below
delete all file from var/cache
and var/view_preprocessed
and page_cache using rm -rf
var/cacheand
rm -rf var/view_preprocessed,
rm -rf var/page_cache`