How to Add Placeholder Text in Field for Checkout Page in Magento 2
Steps to Add Placeholder Text in Field for Checkout Page in Magento 2:
Step 1: First create di.xml file at the given below path
app/code/Vendor/Extension/etc/frontend/di.xml
Now add the code as follows
<?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">
<pluginname="add_placeholderto_checkout" type="Vendor\Extension\Plugin\Block\Checkout\AttributeMerger" sortOrder="10"/>
</type>
</config>
Step 2: Now create a Plugin File at the following path
app/code/Vendor/Extension/Plugin/ Block/ Checkout/ AttributeMerger.php
Then add the following code
<?php
namespace Vendor\Extension\Plugin\Block\Checkout;
class AttributeMerger
{
public function afterMerge(\Magento\Checkout\Block\Checkout\AttributeMerger $subject,$result)
{
$result['firstname']['placeholder'] = __('First Name');
$result['lastname']['placeholder'] = __('Last Name');
$result['street']['children'][0]['placeholder'] = __('Line no 1');
$result['street']['children'][1]['placeholder'] = __('Line no 2');
$result['city']['placeholder'] = __('Enter City');
$result['postcode']['placeholder'] = __('Enter Zip/Postal Code');
$result['telephone']['placeholder'] = __('Enter Phone Number');
return $result;
}
}
At last, clear the cache and check the output on your checkout page.
Comments
Post a Comment