0

I want to change the label of State/Province to just State only in the checkout field in magento 2. I am trying to update it via i18n and insert it in my custom module. But the label is not updated. enter image description here

2

2 Answers 2

0

This link would be helpful for changing labels in shipping fields in the checkout.

How to change checkout page field label in 2.1.7?

I have added the labels in i18n's en_US CSV and that has done my job.

Thanks, @Mujahidh for the link

0

Can do it using AttributeMerger's afterMerge function. Create a basic custom module and add the following file to your module.

Vendor/Module/etc/di.xml

<?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\AttributeMerger">
    <plugin name="checkoutFieldLableChange" type="Vendor\Module\Model\Plugin\AttributeMergerPlugin"/>
</type>

Next create the AttributeMergerPlugin.php file in the following location Vendor\Module\Model\Plugin\AttributeMergerPlugin.php

<?php
namespace Vendor\Module\Model\Plugin;
class AttributeMergerPlugin
{
public function afterMerge(\Magento\Checkout\Block\Checkout\AttributeMerger $subject, $result)
{
    if (array_key_exists('city', $result)) {
        $result['city']['label'] = 'Your Label';
    }
    if (array_key_exists('region_id', $result)) {
        $result['region_id']['label'] = 'Your Label';
    }

    return $result;
}
}

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.