Created
February 16, 2023 18:28
-
-
Save elias1435/85822717f402073ecee594bd51ceb610 to your computer and use it in GitHub Desktop.
How to reorder checkout fields on WooCommerce checkout billing or shipping firleds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( "woocommerce_checkout_fields", "my_reordering_checkout_fields", 15, 1 ); | |
function my_reordering_checkout_fields( $fields ) { | |
## ---- Billing Fields ---- ## | |
// Set the order of the fields | |
$billing_order = array( | |
'billing_first_name', | |
'billing_last_name', | |
'billing_email', | |
'billing_phone', | |
'billing_company', | |
'billing_address_1', | |
'billing_address_2', | |
'billing_postcode', | |
'billing_city', | |
'billing_state', | |
'billing_country' | |
); | |
$count = 0; | |
$priority = 10; | |
// Updating the 'priority' argument | |
foreach($billing_order as $field_name){ | |
$count++; | |
$fields['billing'][$field_name]['priority'] = $count * $priority; | |
} | |
// Change the CSS class | |
$fields['billing']['billing_email']['class'] = array('form-row-first'); | |
$fields['billing']['billing_phone']['class'] = array('form-row-last'); | |
$fields['billing']['billing_postcode']['class'] = array('form-row-first'); | |
$fields['billing']['billing_city']['class'] = array('form-row-last'); | |
## ---- Return the new fields order ---- ## | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment