0

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
  • Is It working for you? Jun 17, 2021 at 11:09

1 Answer 1

1

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.

2
  • 1
    Great,It's working. Thank you so much @Rohan Hapani
    – kanidhaya
    Jun 17, 2021 at 11:16
  • Happy coding !! Jun 17, 2021 at 11:16

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.