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 ?
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.
Under payment method (debit/credit) Recipient Firstname to Customer Firstname and Recipient Lastname to Customer Lastname and so on. Refer my screenshot