I want to move the billing address form below the shipping address in the checkout, on the first page/step.
Therefore I created a custom module with the following LayoutProcessorPlugin.php.
But now the billing address field is displayed above the shipping address instead of below. And the default checkbox 'My billing and shipping address are the same' is now unchecked by default.
Also the line to remove the billing address on the billing step is not working. So now this is displayed on both places.
EDIT:
We also tried to use the Tigren method (https://www.tigren.com/billing-under-shipping-address-m2/) or the SR module (https://github.com/sohelrana09/modified-checkout). But these both have the same problem, the prefix is changed into an input field, instead of a select field. So it does not match the options from the backend anymore.
Image of the prefix input field (should be a select with values from backend):
Any idea how to solve this issue?
My LayoutProcessorPlugin.php code;
<?php
namespace Redable\ReorderBillingForm\Model\Checkout;
class LayoutProcessorPlugin
{
/**
* @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
* @param array $jsLayout
* @return array
*/
public function afterProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
array $jsLayout
)
{
// get billing address form at billing step
$billingAddressForm = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form'];
// move address form to shipping step
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['billing-address-form'] = $billingAddressForm;
// remove form from billing step
unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form']);
return $jsLayout;
}
}
Best Answer
I was able to resolve the issue for Sohel's module with below changes
Go to file app/code/SR/ModifiedCheckout/Plugin/Block/LayoutProcessor.php and update as per below.
Update your constructor as below.
Now update your
aroundProcess
function with below code.Once you are done with above changes, add a new function
convertElementsToSelect
to convert prefix and suffix into a select dropdown.