Support » Plugin: WooCommerce » disable autofocus on first name checkout field

  • Resolved vervelover

    (@vervelover)


    Hi,

    I reordered my checkout fields with a function, my problem is that the “First Name” input field has the autofocus property set by default, how can I disable it?

    It makes no sense to have it enabled if it’s not the first field on the page.

    Thank you
    Alessio

Viewing 8 replies - 1 through 8 (of 8 total)
  • Is this impossible? It doesn’t make sense to allow people to change the checkout field order if autofocus cannot be disabled..

    Hi, I just had this problem. Try this. Works for me. This code will ensure autofocus=”off” is set on First Name.

    /* WOOCOMMERCE: CHECKOUT: DISABLE AUTOFOCUS ON FIRST NAME */
    function disable_autofocus_firstname($fields)
    {
    $fields[‘billing’][‘billing_first_name’][‘autofocus’] = false;
    return $fields;
    }
    add_filter(‘woocommerce_checkout_fields’, ‘disable_autofocus_firstname’);

    @lindenism

    That was it! Thanks a lot!!

    Hi @lindenism @vervelover

    I’ve inserted the code exactly as written above into the functions.php file of the active child theme, but it does not work for me; the autofocus=’autofocus’ attribute remains for the billing_first_name field. Have semantics changed?

    Thanks.

    Hi Svenv,

    that’s the code I use (still working):

    // Hook in
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
         
         $fields['billing']['billing_first_name']['autofocus'] = 'false';
    
         return $fields;
    }
    Iamhere

    (@iamhere)

    I am using the woocommerce one page checkout plugin and the woocommerce checkout field editor.

    This function worked great to remove the auto-focus, which was making the page scroll down past the products!

    Thanks for this.

    This worked perfectly for me, too. I used it as a custom plugin rather than adding it to my functions.php file. That way I can quickly add it to my other sites with WooCommerce installed.

    Thanks for the script!

    • This reply was modified 1 year, 10 months ago by quietcity.

    I had to target the first name on both the billing and shipping to get it to work, but it seems to be doing the trick now!

    /* 
    WOOCOMMERCE > CHECKOUT 
    DISABLE AUTOFOCUS ON FIRST NAMES so that the page doesn't jump down past the products */
    // Hook in
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
         
         $fields['billing']['billing_first_name']['autofocus'] = 'false';
         $fields['shipping']['shipping_first_name']['autofocus'] = 'false';
    
         return $fields;
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘disable autofocus on first name checkout field’ is closed to new replies.