7

I'm trying to apply autocomplete="off" on my WooCommerce checkout fields but it just doesn't work.

Is there a way to do that for the checkout form?

I checked the docs and there's nothing available there. I also tried setting the default value to empty but it doesn't work either. This is when the user is not logged in of course.

enter image description here

UPDATE:

I tried unset as suggested by @smvax but it did not work as well.

add_filter('woocommerce_checkout_fields', 'default_values_checkout_fields');
function default_values_checkout_fields($fields) {
  if (!is_user_logged_in()) {
      unset($fields['billing_city']);
      unset($fields['billing_first_name']);
      unset($fields['billing_last_name']);
      unset($fields['billing_company']);
      unset($fields['billing_address_1']);
      unset($fields['billing_address_2']);
      unset($fields['billing_city']);
      unset($fields['billing_postcode']);
      unset($fields['billing_country']);
      unset($fields['billing_state']);
      unset($fields['billing_email']);
      unset($fields['billing_phone']);
      unset($fields['shipping_city']);
      unset($fields['shipping_first_name']);
      unset($fields['shipping_last_name']);
      unset($fields['shipping_company']);
      unset($fields['shipping_address_1']);
      unset($fields['shipping_address_2']);
      unset($fields['shipping_postcode']);
      unset($fields['shipping_country']);
      unset($fields['shipping_state']);
      return $fields;
  }
}

I also tried the answer here but it's not working as well.

Thanks

Community
  • 1
  • 1
elimariaaa
  • 796
  • 4
  • 10
  • 30

2 Answers2

17

You can use Wordpress '__return_empty_string' with woocommerce_checkout_get_value WooCommerce filter hook to get empty values simply this way:

add_filter('woocommerce_checkout_get_value','__return_empty_string', 1, 1);

This will empty all checkout values, when checkout page is loaded.

The Code goes in functions.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works.

You should reset all existing sessions in Woocommerce settings > System status > tools and also the cache if your e-commerce use any.
Also empty your browser cache and stored data.

Related: Clear only some checkout fields values in Woocommerce

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • thank you for your answer but it's not working when I tried it. I added it in my child theme's functions.php file. My checkout URL: http://dfp-dev.creativequoin.com/checkout/?v=4e45c2af0995 – elimariaaa Apr 10 '17 at 09:25
  • @jeepers_creepers I have tested this code on 3 different WooCommerce websites, and it works on all of them. So there is certainly some custom code in your theme or in a third party plugin, that is making a conflict… I have changed the priority in my hook (code). Try it again. I hope it will work as it should. You can test it here on my raw test server: http://www.cbleu.net/sites/tie/shop/ (shop something, then after your 1st order, add something to cart and go to checkout… you will see no data in checkout fields). – LoicTheAztec Apr 10 '17 at 10:38
  • it worked when I added it on my custom Woocommerce plugin. Thanks! – elimariaaa Apr 28 '17 at 03:59
0

You can set autocomplete="off" for the form fields using the woocommerce_checkout_fields filter.

    add_filter('woocommerce_checkout_fields', 'autocomplete_off_checkout_fields');
    function autocomplete_off_checkout_fields($fields) {
          $fields['billing_first_name']['autocomplete'] = 'off';
          return $fields;
      }
    }

This will work on all the woocommerce checkout fields.

  • Note that Chrome browsers will intentionally ignore the "off" value and still apply autocompletion based on what the user has added to Chrome, i.e. payment data or addresses. – Sven Sep 06 '21 at 16:10