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 Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

51 mins ago

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