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.
2 Answers
This link would be helpful for changing labels in shipping fields in the checkout.
I have added the labels in i18n's en_US CSV and that has done my job.
Thanks, @Mujahidh for the link
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;
}
}