How To

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

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.

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

Step 1: Add custom content in the order summary on the checkout page in Magento 2

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
}

Step 2: Add a custom message to the invoice in Magento 2

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>

Step 3: Add a custom message to the credit memo in Magento 2

 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>

Step 4: Run CLI command in Magento 2

Once the above files are created, kindly run the below command

sudo php bin/magento cache:flush

Result:

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

Conclusion:

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!

Click to rate this post!
[Total: 3 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

2 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

2 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

3 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

4 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

6 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

6 days ago