Skip to content

Instantly share code, notes, and snippets.

@bavington
Last active May 25, 2021 09:56
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bavington/f325d5bee9325001bba3 to your computer and use it in GitHub Desktop.
Save bavington/f325d5bee9325001bba3 to your computer and use it in GitHub Desktop.
Reorder Checkout Fields in WooCommerce
// Reorder Checkout Fields
add_filter('woocommerce_checkout_fields','reorder_woo_fields');
function reorder_woo_fields($fields) {
$fields2['billing']['billing_email'] = $fields['billing']['billing_email'];
$fields2['billing']['billing_first_name'] = $fields['billing']['billing_first_name'];
$fields2['billing']['billing_last_name'] = $fields['billing']['billing_last_name'];
$fields2['billing']['billing_country'] = $fields['billing']['billing_country'];
$fields2['billing']['billing_address_1'] = $fields['billing']['billing_address_1'];
$fields2['billing']['billing_address_2'] = $fields['billing']['billing_address_2'];
$fields2['billing']['billing_city'] = $fields['billing']['billing_city'];
$fields2['billing']['billing_postcode'] = $fields['billing']['billing_postcode'];
$fields2['billing']['billing_state'] = $fields['billing']['billing_state'];
$fields2['billing']['billing_phone'] = $fields['billing']['billing_phone'];
$fields2['shipping']['shipping_first_name'] = $fields['shipping']['shipping_first_name'];
$fields2['shipping']['shipping_last_name'] = $fields['shipping']['shipping_last_name'];
$fields2['shipping']['shipping_country'] = $fields['shipping']['shipping_country'];
$fields2['shipping']['shipping_address_1'] = $fields['shipping']['shipping_address_1'];
$fields2['shipping']['shipping_address_2'] = $fields['shipping']['shipping_address_2'];
$fields2['shipping']['shipping_city'] = $fields['shipping']['shipping_city'];
$fields2['shipping']['shipping_postcode'] = $fields['shipping']['shipping_postcode'];
$fields2['shipping']['shipping_state'] = $fields['shipping']['shipping_state'];
// Add full width Classes and Clears to Adjustments
$fields2['billing']['billing_email'] = array(
'label' => __('Email', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
$fields2['billing']['billing_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields2;
}
Copy link

ghost commented May 17, 2016

This is great, exactly what I was looking for! However, I changed the code a little, because there now are additional fields inside the original $fields array. This way new array keys are sent through the function instead of being cut out.

$checkout_fields = array_merge( $fields, $fields2 );
return $checkout_fields;

@hannahanna
Copy link

hannahanna commented May 27, 2016

Hi and thank you sooo much for this! I 've been looking for this for a several days now...
Just one question; Am I supposed to put this in /webbshop.se/wp-content/plugins/woocommerce/templates/checkout/form-checkout.php ?
Because I can not find woo-checkout-fields.php in the Checkout Fields plugin.

Have a nice weekend! :)

@adiakritos
Copy link

there is a 'clear' element that is injected in the center of the form. How do I remove that?

@jchrislemmer
Copy link

Thanks for this! Works great!

@catbadger
Copy link

Thank you. This saved my butt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment