How To

Magento 2: How to Add Custom Notice on Billing Address and Shipping Address Phone No Field

Hello Magento Friends,

In this blog, we will learn about How to Add Custom Notice on Billing Address and Shipping Address Phone No Field in Magento 2.

The customer’s phone numbers are very valuable. Getting customer phone numbers during order placement helps to contact them for any delivery issue or future communication.

You can set the phone number input field format on the checkout page using Input Mask in Checkout Telephone Field in Magento 2.

Set custom instructions for the phone number field input on the billing and shipping addresses in Magento 2 using the steps below. 

Steps to Add Custom Notice on Billing Address and Shipping Address Phone No Field in Magento 2:

Step 1: Go to the below file path

app\code\Vendor\Extension\etc\di.xml

Now add the code as given below

<?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>

Step 2: Now move to the following file path

app\code\Vendor\Extension\Model\Checkout\LayoutProcessorplugin.php

Then add the code as follows

<?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']['telephone']['notice'] = __('Enter Number With Country code & without any sign. e.g:-(91xxxxxxx09)');
       
        if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['payments-list']['children'])) 
        {
            foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] as $key => $payment) 
            {                
                $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'][$key]['children']['form-fields']['children']['telephone']['notice'] = __('Enter Number With Country code & without any sign. e.g:-(91xxxxxxx09)');                
            } 

        }   
        return $jsLayout;
    }
}

Step 3: After that, run the below commands

php bin/magento setup:di:compile
php bin/magento cache:flush

Conclusion:

Hopefully, using the above method, you can Add Custom Notice on Billing Address and Shipping Address Phone No Field in Magento 2. If you have any difficulty, share the problem with me through the comment box. Stay in touch with us for Magento Customization.

Happy Coding!

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

Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide

Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…

7 hours ago

Enhancing Web Application Security with Laravel’s Built-In Features

In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…

1 day ago

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

October was an exciting month for MageComp! From significant updates across our Magento 2 extension…

1 day ago

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

1 week ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

1 week ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

2 weeks ago