4

enter image description here

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

3

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

0

According to this topic How do you edit checkout field labels in Magento 2? (sorry, wouldn't let me post as comment)

Translation for State/Province and Zip/Postal Code is found (by default) in /vendor/magento/module-checkout/i18n directory.

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

Then find the text and change its translation.

After saving file, don't forget to remove content from /var/cache folder and /var/page_cache folder.

0

You can overwrite below function for changing the Label at cart page in the file: vendor/magento/module-checkout/Block/Cart/LayoutProcessor.php

public function process($jsLayout)
    {
        $elements = [
            'city' => [
                'visible' => $this->isCityActive(),
                'formElement' => 'input',
                'label' => __('City'),
                'value' =>  null
            ],
            'country_id' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('Country'),
                'options' => [],
                'value' => null
            ],
            'region_id' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('State/Province'),
                'options' => [],
                'value' => null
            ],
            'postcode' => [
                'visible' => true,
                'formElement' => 'input',
                'label' => __('Zip/Postal Code'),
                'value' => null
            ]
        ];

        if (!isset($jsLayout['components']['checkoutProvider']['dictionaries'])) {
            $jsLayout['components']['checkoutProvider']['dictionaries'] = [
                'country_id' => $this->countryCollection->loadByStore()->toOptionArray(),
                'region_id' => $this->regionCollection->addAllowedCountriesFilter()->toOptionArray(),
            ];
        }

        if (isset($jsLayout['components']['block-summary']['children']['block-shipping']['children']
            ['address-fieldsets']['children'])
        ) {
            $fieldSetPointer = &$jsLayout['components']['block-summary']['children']['block-shipping']
            ['children']['address-fieldsets']['children'];
            $fieldSetPointer = $this->merger->merge($elements, 'checkoutProvider', 'shippingAddress', $fieldSetPointer);
            $fieldSetPointer['region_id']['config']['skipValidation'] = true;
        }
        return $jsLayout;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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