Skip to content

Instantly share code, notes, and snippets.

@magevision
Last active October 29, 2018 15:33
Show Gist options
  • Save magevision/2bc4f22044d65ba714b46169dd540bc1 to your computer and use it in GitHub Desktop.
Save magevision/2bc4f22044d65ba714b46169dd540bc1 to your computer and use it in GitHub Desktop.
ChangeOrderOfAddressFieldsInCheckout
<?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="magevision_checkout_address_fields_order" type="MageVision\Blog33\Plugin\Checkout\Block\LayoutProcessor" />
</type>
</config>
<?php
namespace MageVision\Blog33\Plugin\Checkout\Block;
class LayoutProcessor {
/**
* Position the telephone field after address fields
*
* @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
* @param array $jsLayout
*
* @return array
*/
public function afterProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
array $jsLayout
) {
//Shipping Address
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']
['children']['telephone']['sortOrder'] = 75;
//Billing Address on payment method
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children']
)) {
$paymentList = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children'];
foreach ($paymentList as $key => $payment) {
/* telephone */
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children'][$key]['children']['form-fields']['children']
['telephone']['sortOrder'] = 75;
}
}
//Billing Address on payment page
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']
)) {
/* telephone */
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']
['children']['telephone']['sortOrder'] = 75;
}
return $jsLayout;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment