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

8
  • Nkatry ka na nito jeepers? :) stackoverflow.com/questions/36694355/… Commented Apr 10, 2017 at 4:00
  • @smzvax I just tried unset and the whole form went missing. Commented Apr 10, 2017 at 4:41
  • how about adding [‘clear’] as shown here: surpriseazwebservices.com/edit-woocommerce-checkout-fields Commented Apr 10, 2017 at 4:58
  • @jeepers_creepers, where are you adding the AUTOCOMPLETE = "off" attribute ? Commented Apr 10, 2017 at 5:04
  • @MayankRaj on the <form> Commented Apr 10, 2017 at 5:11

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

3 Comments

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: dfp-dev.creativequoin.com/checkout/?v=4e45c2af0995
@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: 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).
it worked when I added it on my custom Woocommerce plugin. Thanks!
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.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.