Home > Net >  Woocommerce - Turn Off Autocomplete in Checkout Fields via "autocomplete=new-password"
Woocommerce - Turn Off Autocomplete in Checkout Fields via "autocomplete=new-password"

Time:08-12

I've found a couple of coding examples of this but nothing has worked. It seems such a simple thing to fix. We have an issue with our checkout page when certain users we're guessing have autocomplete on in their browser when checking out, we get duplicate or different Address 1 and 2 values. Even enabling the google api to help with autocomplete, didn't solve our issue. It corrected it some but, not enough.

This is one version of the solution I found in the interwebs melded with my own but, does not do anything....

/* Disable autofill address */

add_filter( 'woocommerce_form_field', 'change_autofill', 1, 1 );

function change_autofill( $field) {

$field = str_replace('autocomplete="billing_address_1"', 'autocomplete="new-password"', $field);
return $field; 

}

I would like the ability to pick and choose which input fields to set the autocomplete attribute to "new-password" as I've read this forces all modern browsers to think it's a password field and does not try to fill them. When using inspector, each input field in the checkout has "autocomplete=off" already. That's why we are after this solution, in this manner...

CodePudding user response:

Was able to get this working fully with this code (I was searching the wrong thing):

/* Disable browser autofill on all Woocommerce form fields */

add_filter( 'woocommerce_form_field', 'change_autofill', 1, 1 );

function change_autofill( $field) {

$field = str_replace('autocomplete="off"', 'autocomplete="new-password"', $field);
return $field; 

}

This works because all fields are set with the attribute autocomplete=off it may not work for everyone. Use your inspector tool for each field to see. Whatever autocomplete is set to, is what you want your first start of str_replace searching for.

Cheers!

  • Related