• Resolved sandornemeth

    (@sandornemeth)


    Hi Diego,

    Is it possible to somehow swap the order of the first and lastname in the shipping/billing form?

    I guess it could only be done by a custom code snippet.

    I tried to use the “WooCommerce Checkout Field Editor” plugin, that didn’t help.

    Many thanks in advance.

    Kind Regards
    Sandor

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi Sandor,

    We will review this, maybe an hook or using the same mentioned plugin, we will reply to you as soon as the status changes.

    Best,
    Luiggi

    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

    Plugin Author Diego Versiani

    (@diegoversiani)

    Hi @sandornemeth,

    If you need more instructions on how to add code snippets, please check our knowledge base article:
    https://support.fluidcheckout.com/portal/en/kb/articles/how-to-add-code-snippets

    I’m closing this topic for now. Let us know if you need further support with this.

    Best,
    Diego

    Thread Starter sandornemeth

    (@sandornemeth)

    Hi Diego, sorry, I didn’t get email notification about your reply.
    Many many thanks for the feedback!
    I’ll give 5 stars rating to the plugin. It is awesome.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Swapping firstname and lastname in the shipping/billing form.’ is closed to new replies.