Magento 2 how to change label for firsname field in checkout page. need to change in code level don't want to translation sheet
1 Answer
As you mentioned, you want to change it by code :
Create di.xml file for plugin create :
app/code/Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<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="first_name_change" type="Vendor\Moudle\Block\LayoutProcessor" sortOrder="1"/>
</type>
</config>
Create LayoutProcessor.php file :
app/code/Vendor/Module/Block/LayoutProcessor.php
<?php
namespace Vendor\Module\Block;
class LayoutProcessor
{
/**
* @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
* @param array $jsLayout
* @return array
*/
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']['firstname']['label'] = __('My Name');
return $jsLayout;
}
}
Clean cache and check it.
-
1
-