Skip to content

Instantly share code, notes, and snippets.

@cryptexvinci
Created March 29, 2017 03:01
Show Gist options
  • Save cryptexvinci/2182728ba74c3c4693c294c3d70bac34 to your computer and use it in GitHub Desktop.
Save cryptexvinci/2182728ba74c3c4693c294c3d70bac34 to your computer and use it in GitHub Desktop.
re-order WooCommerce Checkout Fields
add_filter( 'woocommerce_checkout_fields', 'custom_move_checkout_fields' );
function custom_move_checkout_fields( $fields ) {
// Lets display the email first. You can move these around depending on your needs.
$billing_order = array(
"billing_email",
"billing_first_name",
"billing_last_name",
"billing_company",
"billing_address_1",
"billing_address_2",
"billing_postcode",
"billing_country",
"billing_state",
"billing_phone"
);
// This makes sure above orders are maintained.
foreach($billing_order as $billing_field) {
$billing_fields[$billing_field] = $fields["billing"][$billing_field];
}
$fields["billing"] = $billing_fields;
// Re-order this according to your need.
$shipping_order = array(
"shipping_first_name",
"shipping_last_name",
"shipping_company",
"shipping_address_1",
"shipping_address_2",
"shipping_postcode",
"shipping_country",
"shipping_city",
"shipping_state"
);
// This makes sure above orders are maintained.
foreach($shipping_order as $shipping_field) {
$shipping_fields[$shipping_field] = $fields["shipping"][$shipping_field];
}
$fields["shipping"] = $shipping_fields;
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment