Hi Sandor,
The following code snippet changes the order of the names:
/**
* Swap the position of the billing first and last names to display the last name field first.
*/
function fluidcheckout_billing_last_name_first( $checkout_fields ) {
// Remove field size and position classes
if ( false !== ( $key = array_search( 'form-row-first', $checkout_fields['billing']['billing_first_name']['class'] ) ) ) { unset( $checkout_fields['billing']['billing_first_name']['class'][ $key ] ); }
if ( false !== ( $key = array_search( 'form-row-last', $checkout_fields['billing']['billing_last_name']['class'] ) ) ) { unset( $checkout_fields['billing']['billing_last_name']['class'][ $key ] ); }
// Change priority and add new appropriate size and position classes
$checkout_fields['billing']['billing_first_name']['priority'] = 20;
$checkout_fields['billing']['billing_first_name']['class'] = array_merge( $checkout_fields['billing']['billing_first_name']['class'], array( 'form-row-last' ) );
$checkout_fields['billing']['billing_last_name']['priority'] = 10;
$checkout_fields['billing']['billing_last_name']['class'] = array_merge( $checkout_fields['billing']['billing_last_name']['class'], array( 'form-row-first' ) );
return $checkout_fields;
}
add_filter( 'woocommerce_checkout_fields', 'fluidcheckout_billing_last_name_first', 200 );
/**
* Swap the position of the shipping first and last names to display the last name field first.
*/
function fluidcheckout_shipping_last_name_first( $checkout_fields ) {
// Remove field size and position classes
if ( false !== ( $key = array_search( 'form-row-first', $checkout_fields['shipping']['shipping_first_name']['class'] ) ) ) { unset( $checkout_fields['shipping']['shipping_first_name']['class'][ $key ] ); }
if ( false !== ( $key = array_search( 'form-row-last', $checkout_fields['shipping']['shipping_last_name']['class'] ) ) ) { unset( $checkout_fields['shipping']['shipping_last_name']['class'][ $key ] ); }
// Change priority and add new appropriate size and position classes
$checkout_fields['shipping']['shipping_first_name']['priority'] = 20;
$checkout_fields['shipping']['shipping_first_name']['class'] = array_merge( $checkout_fields['shipping']['shipping_first_name']['class'], array( 'form-row-last' ) );
$checkout_fields['shipping']['shipping_last_name']['priority'] = 10;
$checkout_fields['shipping']['shipping_last_name']['class'] = array_merge( $checkout_fields['shipping']['shipping_last_name']['class'], array( 'form-row-first' ) );
return $checkout_fields;
}
add_filter( 'woocommerce_checkout_fields', 'fluidcheckout_shipping_last_name_first', 200 );
We recommend using the plugin Code Snippets to add the filter, that way it wont be lost if you update your theme.
Let me know if that solution worked.
Best,
Luiggi