2

How to change label : Firstname to Customer Firstname

only on checkout/payment page for payment method ( ex:paypal, debit/credit card,cash on delivery) in magento2.1.7 ?

1

You can do this way. Create preference of class Magento\Checkout\Block\LayourProcessor.php

LayoutProcessor.php

<?php
namespace Vendor\Module\Block;
class LayoutProcessor extends \Magento\Checkout\Block\Checkout\LayoutProcessor 
{ 
 /**
 * Process js Layout of block
 *
 * @param array $jsLayout
 * @return array
 */
public function process($jsLayout)
{
    $attributesToConvert = [
        'prefix' => [$this->getOptions(), 'getNamePrefixOptions'],
        'suffix' => [$this->getOptions(), 'getNameSuffixOptions'],
    ];

    $elements = $this->getAddressAttributes();
    $elements = $this->convertElementsToSelect($elements, $attributesToConvert);
    // The following code is a workaround for custom address attributes
    if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
        ['payment']['children'])) {
        $billingElements = $this->getAddressAttributes(true); // Fetch customer attributes
        $billingElements = $this->convertElementsToSelect($billingElements, $attributesToConvert);
        $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
        ['payment']['children'] = $this->processPaymentChildrenComponents(
            $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children'],
            $billingElements
        );
    }
    if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['step-config']['children']['shipping-rates-validation']['children'])) {
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['step-config']['children']['shipping-rates-validation']['children'] =
            $this->processShippingChildrenComponents(
                $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
                ['step-config']['children']['shipping-rates-validation']['children']
            );
    }

    if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
        ['children']['shippingAddress']['children']['shipping-address-fieldset']['children'])) {
        $fields = $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
        ['children']['shippingAddress']['children']['shipping-address-fieldset']['children'];
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
        ['children']['shippingAddress']['children']['shipping-address-fieldset']['children'] = $this->merger->merge(
            $elements,
            'checkoutProvider',
            'shippingAddress',
            $fields
        );
    }
    return $jsLayout;
}

/**
 * @return array
 */
private function getAddressAttributes($isOnBilling = false)
{
    /** @var \Magento\Eav\Api\Data\AttributeInterface[] $attributes */
    $attributes = $this->attributeMetadataDataProvider->loadAttributesCollection(
        'customer_address',
        'customer_register_address'
    );

    $elements = [];
    foreach ($attributes as $attribute) {
        $code = $attribute->getAttributeCode();
        if ($attribute->getIsUserDefined()) {
            continue;
        }
        $elements[$code] = $this->attributeMapper->map($attribute);
        if (isset($elements[$code]['label'])) {

            if($code == 'firstname' && $isOnBilling) 
                $label = 'Customer First Name';
            elseif($code == 'lastname' && $isOnBilling)
                $label = 'Customer Last Name';
            else
                $label = $elements[$code]['label'];

            $elements[$code]['label'] = __($label);
        }
    }
    return $elements;
}
}

You have to override needed private members as well. Let me know if you need any more help.

|improve this answer|||||
  • Okay sure, i will try this – Amy Nov 8 '18 at 12:03
  • Hi, I have tried this, it's working. but it's changing even on shipping page. i need to change only on Review/Payments page – Amy Nov 8 '18 at 13:00
  • ok let me check – Ramkishan Suthar Nov 8 '18 at 13:42
  • I will be waiting for your comment.. – Amy Nov 8 '18 at 15:27
  • can you please share screenshot where you want this. – Ramkishan Suthar Nov 9 '18 at 8:12
0

Under payment method (debit/credit) Recipient Firstname to Customer Firstname and Recipient Lastname to Customer Lastname and so on. Refer my screenshot

enter image description here

|improve this answer|||||
  • Did you try using locale? – Sohel Rana Nov 10 '18 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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