Magento – How to change checkout page field label in 2.1.7

magento-2.1onepage-checkoutpayment-methodsshipping

enter image description here

I want to change State/Province label. How can I do it?

Best Answer

There are two to possible this.

Way 1: If you want to change the shipping address fields as well as billing address fields, you can do via theme transaction if you have made a custom theme as per your language.

If you have a custom or third party theme:

You might find a CSV file there. If you have kept locale as English(United States) which is a default one, there will be a file named en_US.csv

app\design\frontend\Magento\Themename\i18n

Without theme:

Copy locale's csv file from /vendor/magento/module-checkout/i18n folder to app/code/Magento/module-checkout/i18n directory.

Exapmle:

"First Name","Volunteer First Name"
"Last Name","Volunteer Last Name"

Way 2: If you change made in shipping address fields only, Please override LayoutProcessor.php

Step 1 di.xml

path: app/code/vendor/module_name/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="Custom_Checkout" type="vendor\Module\Block\LayoutProcessor" sortOrder="100"/>
    </type> 
</config>

Step 2: LayoutProcessor.php

path:app/code/vendor/module_name/Block/

         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']['lastname']['label'] = __('Recipient lastname'); 

            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['region_id']['label'] = __('Division'); 

        return $jsLayout;
    }
}

It's work like charm

Related Topic