1

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?

2

I ended up using this code that I found as part of an answer on a different stackexchange question.

/* 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]);

                }
            }

The problem with this is that if a shop uses checkout-agreements that those will also be deleted. Anyone know how to fix this?

  • When using this code the "place order" button is disable – sumeet bajaj Oct 14 at 6:54
0
public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, array $jsLayout) 
{
    $billingConfiguration = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
    ['children']['payment']['children']['payments-list']['children'];

   //Checks if billing step available.
   if (isset($billingConfiguration)) {
      //Iterate over billing forms.
      foreach($billingConfiguration as $key => &$billingForm) {
          //Exclude not billing forms
          if (!strpos($key, '-form')) {
              continue;
          }

            /* $billingForm['children']['form-fields']['children']['company']['visible'] = 0;

            $billingForm['children']['form-fields']['children']['city']['visible'] = 0;
            $billingForm['children']['form-fields']['children']['city']['validation']['required-entry'] = 0;

            $billingForm['children']['form-fields']['children']['region']['visible'] = 0;
            $billingForm['children']['form-fields']['children']['region_id']['visible'] = 0;

            $billingForm['children']['form-fields']['children']['telephone']['visible'] = 0;
            $billingForm['children']['form-fields']['children']['telephone']['value']   = '0000000000';
            $billingForm['children']['form-fields']['children']['telephone']['validation']['required-entry'] = 0;

            $billingForm['children']['form-fields']['children']['country_id']['visible'] = 0;
            $billingForm['children']['form-fields']['children']['country_id']['validation']['required-entry'] = 0; */

            unset($billingForm['children']['form-fields']['children']['company']);
            unset($billingForm['children']['form-fields']['children']['city']);
            unset($billingForm['children']['form-fields']['children']['region']);
            unset($billingForm['children']['form-fields']['children']['region_id']);
            unset($billingForm['children']['form-fields']['children']['telephone']);
            unset($billingForm['children']['form-fields']['children']['street']);
            unset($billingForm['children']['form-fields']['children']['country_id']);

            //unset($billingForm['children']['form-fields']['children']['postcode']);
            //print_r($billingForm['children']['form-fields']); die;
        }
    }

    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.