How to remove billing section from checkout page on Magnto2.4.5
1 Answer
Create di.xml file
<?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\Module\Plugin\Checkout\BillingRemoveAddress" sortOrder="1"/>
</type>
</config>
Create BillingRemoveAddress.php
<?php
namespace Vendor\Module\Plugin\Checkout;
use Magento\Checkout\Block\Checkout\LayoutProcessor;
class BillingRemoveAddress
{
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;
}
}
and check it.