1

The site I am working on is only selling to UK customers, and therefore we would like to change the labels from the Zip/Postal to Postcode and from State/Province to County.

I have spent a long time looking through the code with very little success, although I have also read online that it may be stored in the database somewhere?

3 Answers 3

2

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;
    }
1

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

For 2.4 the labels can be change from DB eav_attribute table column frontend_label

Thanks

Your Answer

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

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