Let’s initiate a discussion!!
By performing below steps one-by-one, we can put any validation in the checkout billing address.
In this example, we are going to set validation for the telephone field.
Here validation will be about the maximum and minimum length of telephone Exact ten digits going to get allowed.
First, you have to create a file in your existing module following to below path,
1 |
app\code\[VendorName]\[ModuleName]\etc\frontend\di.xml |
1 2 3 |
<type name="Magento\Checkout\Block\Checkout\LayoutProcessor"> <plugin disabled="false" name="checkout_billing_address_layoutProcessor" sortOrder="110" type="[VendorName]\[ModuleName]\Plugin\Block\Checkout\LayoutProcessor"/> </type> |
Then, you have to create another file at a given path,
1 |
app\code\[VendorName]\[ModuleName]\Plugin\Block\Checkout\LayoutProcessor.php |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php namespace [VendorName]\[ModuleName]\Plugin\Block\Checkout; class LayoutProcessor { public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, array $jsLayout) { if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payment']['children']['payments-list']['children'] )) { foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payment']['children']['payments-list']['children'] as $key => $payment) { /* Telephone Billing Address */ if (isset($payment['children']['form-fields']['children']['telephone'])) { $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payment']['children']['payments-list']['children'][$key]['children']['form-fields']['children'] ['telephone']['validation'] = ['required-entry' => true, 'min_text_length' => 10, 'max_text_length' => 10]; } } } return $jsLayout; } } |
After doing the above steps you need to run below command:
1 2 |
php bin/magento cache:flush php bin/magento cache:clean |
You can also put validations for other fields. All that you need to do is to change the field name in the form-field section. You can also change default validation error message using .csv in your module.
[crayon-64217f0f389d3965358177/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.