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

How to Add a custom comment in Magento 2 check out 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.

Previous Article

Top 7 Popular Payment Methods in Magento 2

Next Article

How to Export data into CSV file Programmatically in Magento 2

Write a Comment
  1. 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.

Leave a Comment

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

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨