Magento 2: How Can I Add Field Notice To Checkout Fields?
-
14-04-2021 - |
Pergunta
I'd like to add a comment to some checkout fields on Magento 2.1.10
without using tooltips (that I need to remove). So I edited the checkout_index_index.xml
and in shipping-address-fieldset section I've added the following:
<item name="shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<item name="telephone" xsi:type="array">
<item name="config" xsi:type="array">
<item name="tooltip" xsi:type="boolean">false</item>
</item>
</item>
<item name="company" xsi:type="array">
<item name="config" xsi:type="array">
<item name="notice" xsi:type="string">My notice</item>
</item>
</item>
</item>
</item>
Tooltip is hidden but no notice appears...
Any help would be very appreciated...
Solução
To do this, you can add a custom template for a specific form field. This is perfectly explained in the Magento 2 devdocs. Take a look here: http://devdocs.magento.com/guides/v2.2/howdoi/checkout/checkout_edit_form.html
Outras dicas
1.Create a di.xml under 'etc' directory of your any custom module
<?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\LayoutProcessor">
<plugin name="rewrite-checkout-fields" type="Namespace\Module\Model\Checkout\LayoutProcessorPlugin" sortOrder="10"/>
</type>
</config>
2.Create a file called LayoutProcessorPlugin.php file under 'Namespace/Module/Model/Checkout'.
<?php
namespace Namespace\Module\Model\Checkout;
class LayoutProcessorPlugin
{
/**
* @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']['notice'] = __('Please enter first name here');
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['lastname']['notice'] = __('Please enter last name here');
return $jsLayout;
}
}
Note: here i add comment below first and last name you can do for others too.Please accept and vote if use full to you this will help others too.