In the payment step under checkout in Magento 2, I'm trying to remove the address and the option: 'My billing and shipping address are the same '. Because I have added billing address to shipping step.
I got a LayoutProcessor.php
and I'm trying to edit the $jsLayout
but I'm unsure if this is the way to go and what path to unset it at.
I currently got the following code which doesn't work yet. It's in the aroundprocess
function.
if (isset($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list'])) {
$componentBilling = $jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'];
foreach ($componentBilling as $keyBilling => $value) {
if (preg_match('/-form/', $keyBilling)) {
unset($componentBilling[$keyBilling]['children']['form-fields']);
}
}
}
Thanks in advance!
P.s. for anyone who is curious about how to move the billing address to the shipping step. I followed this guide.
Update: I did find this option: In admin under Stores -> Configuration -> Sales -> Checkout -> Checkout Options -> Display Billing Address On .. change it to Payment Page. And then add the following code
unset($jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']);
But I would prefer a prettier option where no settings have to be changed in the admin, so if anyone knows anything?