skip to Main Content

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…

2

Answers


  1. Chosen as BEST ANSWER

    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!


  2. Just a comment regarding the approved answer, it should be:

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

    instead of:

    $field = str_replace('autocomplete="off"', 'autocomplete="new-password"', $field);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search