3

how can i add notice or lable in checkout page below the state field just like notice below the email address in blow image,

state input element is created by region_id field in vendor\magento\module-checkout\view\frontend\layout\checkout_index_index.xml

<item name="customEntry" xsi:type="string">shippingAddress.region</item>

enter image description here

1 Answer 1

6

1.Create a di.xml under 'etc' directory of your any custom module

<?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="Namespace\Module\Model\Checkout\LayoutProcessorPlugin" sortOrder="10"/>
    </type>
</config>

2.Create a file called LayoutProcessorPlugin.php file under 'Namespace/Module/Model/Checkout'.

<?php
namespace Namespace\Module\Model\Checkout;

class LayoutProcessorPlugin
{
    /**
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */

    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'] = __('Please enter first name here'); 
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['lastname']['notice'] = __('Please enter last name here'); 
        return $jsLayout;
    }
}

Note: here i add comment below first and last name you can do for others too.Please accept and vote if use full to you this will help others too.enter image description here

18
  • Please vote as well if acceptable will help to others. Aug 29, 2018 at 10:21
  • Thankyou it work for me, but it is not working with state/province field and i need this for that field only
    – Hiren
    Aug 29, 2018 at 11:39
  • I checked just now it is coming also on state/provice use this: $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'] ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['region_id']['notice'] = __('Please choose Province'); Aug 29, 2018 at 11:51
  • actually in my case it is coming dynamically where State is Required
    – Hiren
    Aug 29, 2018 at 11:56
  • ok but it should work for all because it takes name element from field and add notice on that below the particular field. Aug 29, 2018 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.