Admin Sales Order View, Invoice & Credit Memo How To Add Custom Message In Magento 2   

Hello Everyone,

In this blog, we will learn about how to Add Custom Message to Admin Sales Order View, Invoice and Credit Memo in Magento 2.

Store owners improve their store admin panel by customized the admin functionality like adding/removing columns, grid etc.

Adding custom elements to the admin panel makes admin work more easily. 

Without wasting your time, let us guide you straight away. Follow the easy step given below to Add Custom Message to Admin Sales Order View, Invoice and Credit Memo in Magento 2.

STEPS FOR ADD CUSTOM MESSAGE TO ADMIN SALES ORDER VIEW, INVOICE AND CREDIT MEMO IN MAGENTO 2

For Sales Order View:

Step 1: Create layout file sales_order_view.xml

app/code/Vendor/Extension/view/adminhtml/layout/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\Extension\Block\Adminhtml\Order\View\CustomMessage" name="sales_order_view_custom_msg"

                   template="order/view/customMessage.phtml"/>

        </referenceBlock>

    </body>

</page>

For Sales Order Invoice:

Step 2: Create layout file sales_order_invoice.xml

app/code/Vendor/Extension/view/adminhtml/layout/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\Extension\Block\Adminhtml\Order\View\CustomMessage" name="invoice_view_custom_msg"

                   template="order/view/customMessage.phtml"/>

        </referenceBlock>

    </body>

</page>

For Sales Order CreditMemo:

Step 3: Create layout file sales_order_creditmemo.xml

app/code/Vendor/Extension/view/adminhtml/layout/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\Extension\Block\Adminhtml\Order\View\CustomMessage" name="credirmemo_view_custom_msg"

                   template="order/view/customMessage.phtml"/>

        </referenceBlock>

    </body>

</page>

Step 4: Create CustomMessage.php file

app/code/Vendor/Extension/Block/Adminhtml/Order/View/customMessage.php

<?php

namespace Vendor\Extension\Block\Adminhtml\Order\View;

class CustomMessage extends \Magento\Backend\Block\Template

{

    // Here you can fetch order detail if you want to display in order information as an extra detail

}

Step 5: Create customMessage.phtml file

app/code/Vendor/Extension/view/adminhtml/templates/order/view/customMessage.phtml

<h3>This order contains gift</h3>

Step 6: Finally run the below commands

$ php bin/magento cache:clean

$ php bin/magento cache:flush

Step 7: Output:

Sales Order View:

Final Thoughts:

So this was the easiest way which we have told you in this blog. This is how you can Add Custom Message to Admin Sales Order View, Invoice and Credit Memo in Magento 2. Hope you liked the blog.

So quickly go to the comment box and tell me how you like this blog?

Stay tuned with us on our site to get new updates of Magento.

Thanks for reading and visiting our site.    

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Leave a Reply

Your email address will not be published. Required fields are marked *