0

I want to disable the "Billing address" from checkout page in Magento 2.

enter image description here

1 Answer 1

0

For hidden billing address fields (form), but it still do some extra work for validation.

etc/di.xml

<?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="disable_billing_address" type="Vender\DisableBillingAddress\Plugin\DisableBillingAddress" sortOrder="100"/>
    </type>
</config>

Plugin/DisableBillingAddress.php

<?php
declare(strict_types=1);

namespace Vender\DisableBillingAddress\Plugin;

use Magento\Checkout\Block\Checkout\LayoutProcessor as M2LayoutProcessor;
use Magento\Framework\Stdlib\ArrayManager;

class DisableBillingAddress
{
    private $arrayManager;

    public function __construct(
        ArrayManager $arrayManager
    ) {
        $this->arrayManager = $arrayManager;
    }

    public function afterProcess(M2LayoutProcessor $subject, $jsLayout)
    {
        // Billing Address fields
        $paths = $this->arrayManager->findPaths('form-fields', $jsLayout);
        foreach ($paths as $path) {
            $jsLayout = $this->arrayManager->remove($path, $jsLayout);
        }

        return $jsLayout;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.