How to Add Custom Message to Admin Sales Order View, Invoice, and Credit Memo in Magento 2

How to Add Custom Message to Admin Sales Order View, Invoice, and Credit Memo in Magento 2

  • Method to add a custom message to admin sales order view

Create sales_order_view.xml

Directory

Vendor/Module/view/adminhtml/layout/sales_order_view.xml

Content of sales_order_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="order_info">
<block class="Vendor\Module\Block\Adminhtml\Order\View\CustomMessage" name="sales_order_view_custom_msg"
template="order/view/customMessage.phtml"/>
</referenceBlock>
</body>
</page>
  • Method to add a custom message to the invoice

Create sales_order_invoice.xml

Directory

Vendor/Module/view/adminhtml/layout/sales_order_invoice.xml

Content of sales_order_invoice.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">
<block class="Vendor\Module\Block\Adminhtml\Order\View\CustomMessage" name="invoice_view_custom_msg"
template="order/view/customMessage.phtml"/>
</referenceBlock>
</body>
</page>
  • Method to add a custom message to the credit memo 

Create sales_order_creditmemo.xml

Directory

Vendor/Module/view/adminhtml/layout/sales_order_creditmemo.xml

Content of sales_order_creditmemo.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">
<block class="Vendor\Module\Block\Adminhtml\Order\View\CustomMessage" name="credirmemo_view_custom_msg"
template="order/view/customMessage.phtml"/>
</referenceBlock>
</body>
</page>

Create CustomMessage.php

Directory

Vendor/Module/Block/Adminhtml/Order/View/CustomMessage.php

Content of CustomMessage.php

<?php
namespace VendorName\ModuleName\Block\Adminhtml\Order\View;
class customMessage extends \Magento\Backend\Block\Template
{
// write the code here to show the order detail
}

Create customMessage.phtml

Directory

Vendor/Module/view/adminhtml/templates/order/view/customMessage.phtml

Content of customMessage.phtml

<h3>You can set the Message here</h3>

 

We are providing the best Magento 2 Services in UK for International Clients. If you are looking for Magento Developers, visit Magento Development Agency.
Related Products