cancel
Showing results for 
Search instead for 
Did you mean: 

Removing billing address from payment method without removing agreements.

SOLVED

Removing billing address from payment method without removing agreements.

I'm looking to remove the billing address from the payment-step. I moved the option to add a billing address to the shipping step.

 

Now I know there is an option in the admin: 

/* config: stores/configuration/sales/checkout/checkout-options/display_billing_address_on = payment_page */

But I want it to work even if that option is not selected.

 

I am able to unset the billing address from all payment methods but that also removes the checkout_agreement field.

 

 /* config: checkout/options/display_billing_address_on = payment_method */
if (isset($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children']
)) {
foreach ($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children'] as $key => $payment) {

unset($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children'][$key]);
}
}  

 

How can change this so the checkout_agreements stay? I would prefer a pretty solution, not just hide it in the CSS and would also love to be able to only change files in my module so it is easy to implement. I feel like I have to change checkout_index_index under Magento_Checkout_Agreements and that I should do something with the displayArea in there but i'm not sure what. I would love an option like what the config option does with the billing address. So an option to move the agreements to the bottom of the page. Or just delete the billing address area and leave the agreements alone.

 

Can anyone help me?

4 REPLIES

Re: Removing billing address from payment method without removing agreements.

Try with below code for agreements block to prevent in checkout page,

 if (isset($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children']
)) {
    foreach ($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] as $key => $payment) {

                if($key == 'before-place-order') {
                    foreach ($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children']['before-place-order']['children'] as $key => $payment) {
                        if($key == 'agreements') {
                            continue;
                        }
                    }
                }
                unset($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']
                    ['payment']['children']['payments-list']['children'][$key]);
    }
} 

 I have updated my answer please check again, Replace return true with continue.

If Issue Solved, Click Kudos/Accept As solutions.

Re: Removing billing address from payment method without removing agreements.

Thanks for the quick response. Sadly I get an error: 

Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /home/bigbridgedev/domains/mage223.bigbridgedev.nl/public_html/vendor/magento/module-checkout/Model/Layout/AbstractTotalsProcessor.php on line 44  

Phpstorm complains about the return value being a bool and expecting an array and the 'payment' and 'key' used in the foreach inside while also being used by the outer foreach. Do you know how to fix that? Thanks in advance.

Re: Removing billing address from payment method without removing agreements.

Ah you changed the code and now it works, thanks Smiley Very Happy

Re: Removing billing address from payment method without removing agreements.

-- Gone --