Hello Magento Friends,
In today’s article, I will be providing a solution for Magento 2: Add Custom Message to Admin Sales Order View, Invoice, and Credit Memo.
Customization is the number one feature of Magento 2. Not only the storefront but also the admin panel can be customized as per the requirements. Adding custom elements to the admin panel makes the admin work easy and more understandable.
Admin can add custom columns, elements, messages, and components in the admin grid. It will help the admin efficiently manage and fulfill orders.
Here we will be adding a custom message to the admin sales order view, invoice, and credit memo in the Magento 2 admin grid.
Contents
Go to the below file path
app\code\Vendor\Extension\view\adminhtml\layout\sales_order_view.xml
Then add the below code
<?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\Extension\Block\Adminhtml\Order\View\CustomContent" name="sales_order_view_customcontent" template="order/view/custom_content.phtml"/> </referenceBlock> </body> </page>
Now navigate to the below file path
app\code\Vendor\Extension\view\adminhtml\templates\order\view\custom_content.phtml
And add your custom content
<h3>Add any of your custom content</h3>
Next move to the following file path
app\code\Vendor\Extension\Block\Adminhtml\Order\View\ CustomContent.php
Then add the code as follows
<?php namespace Vendor\Extension\Block\Adminhtml\Order\View; class CustomContent extends \Magento\Backend\Block\Template { // Here you can fetch order detail and add conditions as per your requirement and can use in template file }
For that, you need to create an invoice layout file
Go to the below file path
app\code\Vendor\Extension\view\adminhtml\layout\sales_order_invoice_view.xml
Add the code mentioned below
<?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\Extension\Block\Adminhtml\Order\View\CustomContent" name="sales_invoice_view_customcontent" template="order/view/custom_content.phtml"/> </referenceBlock> </body> </page>
You need to create a credit memo layout file
Navigate to the below-mentioned file path
app\code\Vendor\Extension\view\adminhtml\layout\sales_order_creditmemo_view.xml
Append the code as follows
<?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="sales_creditmemo_view_customcontent" template="order/view/custom_content.phtml"/> </referenceBlock> </body> </page>
Once the above files are created, kindly run the below command
sudo php bin/magento cache:flush
After performing all the steps successfully, you can see that your custom message is added.
Custom message on Magento 2 Admin sales order view
Custom message on Magento 2 invoice
Custom message on Magento 2 credit memo
Accordingly you can include your custom message in the admin sales order view, invoice, and credit memo in Magento 2.
Add more customization to the admin sales order view with the below elements
Need any further customization for your Magento 2 store? Contact us
Happy Coding!
In the world of business, understanding financial metrics is crucial for making informed decisions and…
Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…
In this era, businesses are always on the lookout for ways to engage with their…
Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…
E-commerce has transformed the way consumers shop for products and services and interact with businesses.…
The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…