Change Autofocus Field at Checkout in WooCommerce

Recently WooCommerce has added an autofocus action to the Billing First Name field at checkout. This means when you load the checkout page than keyboard cursor goes automatically to Billing First Name. This is not always ideal, especially if you add new fields to the checkout before that one than what to do. In the example below, I’m removing the autofocus from Billing First Name and assigning it to the Billing Email field instead. Let’s have a look at the following piece of code which shows Autofocus to the Billing Email field.

Add this code in your theme’s functions.php file of your active child theme (or theme).

add_filter( 'woocommerce_checkout_fields', 'change_autofocus_checkout_field' );
 
function change_autofocus_checkout_field( $fields ) {
$fields['billing']['billing_first_name']['autofocus'] = false;
$fields['billing']['billing_email']['autofocus'] = true;
return $fields;
}

Leave a Comment

Scroll to Top