How To

How to Add a custom comment in Magento 2 checkout shipping address fields

With the growing use of the Internet, lots of store owner started switching online to reach a broader audience and gain more sales. And shoppers have grown more tech-savvy and with increased expectations. Nowadays, modern consumers don’t differentiate between offline store shopping versus online shopping. But doing online shopping has its own advantages compared to visiting and shop via an offline store. Also, the interesting fact is customer always remember unique shopping experience with easy flow to grab product. And Yeah, it always ends at Magento customization.

Recently, while working with one of the stores, the owner is willing to add some instructions or you can say comments to under checkout shipping address fields to avoid confusions and he was right at his place based on an issue he was facing. We thought it might help to other store owners like you, so we decided to write a short article on adding a custom comment in Magento 2 checkout shipping address field.

On a First step, you need to create a “di.xml” under this folder.
app\code\vendor\extensions\etc

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
     <plugin name="rewrite-checkout-fields" type="Vendor\Extension\Model\Checkout\LayoutProcessorPlugin" sortOrder="10"/>
    </type>
</config>

At Second step or last step, you need to create another file name “LayoutProcessorPlugin.php” at below path.
app\code\Vendor\Extension\Model\Checkout

<?php
namespace Vendor\Extension\Model\Checkout;
 
class LayoutProcessorPlugin
{
    public function afterProcess(
        \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
     array  $jsLayout
    ) {
     $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['firstname']['notice'] = __('You can not change your name once account is created.');
     $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['lastname']['notice'] = __(' You another Comment goes here');
     return $jsLayout;
    }
}

You can use this code to add one or more comment to Magento 2 checkout shipping fields as per need.

Lastly, hit that falling stars if the code worked for you and don’t forget to comment down below if you are looking for any help regarding this code. Happy Coding.

Click to rate this post!
[Total: 10 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.?

View Comments

  • This is the simplest solution to add a custom comment in Magento 2 checkout shipping fields. You think out of box and i really appreciate your efforts for sharing this valuable information.

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

3 days ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

4 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

5 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

7 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

1 week ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago