How to Remove Field in Billing Address From Checkout in Magento 2
As an online store owner, it is your responsibility to optimize the checkout step and make it easy for the customer to complete their order.
According to Baymard, 21% of US online shoppers have abandoned an order in the past quarter solely due to a “too long/complicated checkout process”.
A complex checkout process can break a sale and prompt customers to bounce to your competitor.
In order to avoid such things in Magento 2 store, remove the extra fields that are unnecessary for your business.
For example, if you are offering a downloadable product type, you can afford to remove the city field. Downloadable products need not get delivered to a physical address.
Depending on the business requirements, you may skip collecting customer details on the checkout that are not necessary for marketing purpose or for order completion.
The programmatic solution to remove field in billing address from checkout in Magento 2 is given below using layoutprocesser.
Solution to Remove Field in Billing Address From Checkout in Magento 2:
- Create di.xml file at app/code/vendor/Exenstion/etc/frontend
1234567891011<? 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="remove_checkout_billing_address_fields"type="vendor\Exenstion\Plugin\Checkout\BillingAddressLayoutProcessor" sortOrder="1"/></type></config> - Create BillingAddressLayoutProcessor.php file at app/code/vendor/Exenstion/Plugin/Checkout
1234567891011121314151617181920212223242526272829303132333435<?phpnamespace vendor\Exenstion\Plugin\Checkout;use Magento\Checkout\Block\Checkout\LayoutProcessor;class BillingAddressLayoutProcessor{public function afterProcess(LayoutProcessor $subject,array $result){$this->result = $result;$billingConfiguration = &$this->result['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'];if (isset($billingConfiguration)) {foreach ($billingConfiguration as $key => &$billingForm) {if (!strpos($key, '-form')) {continue;}if ($billingForm['children']['form-fields']['children']['remove_field']) {unset($billingForm['children']['form-fields']['children']['city']);}}}return $this->result;}}
That’s it.
Questions related to this post? Feel free to ask in the Comment section below.
I would be happy to answer your questions.
Do consider sharing this post with Magento Community via social media.
Thank you.
Also Read: How to Dynamically Change Billing Address in Magento 2
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
Hi, is possible remove all billing address for virtual product?
Thanks
Hello Vitor,
Yes, it is possible but it will throw validation error while order placing.
Thank You