I use below code to disable Autocomplete Fields in the woocommerce checkout page:
add_filter('woocommerce_checkout_get_value','__return_empty_string',10);
Above code disables all autocomplete fields. How about I want to enable autocomplete for specific fields like Billing Country and Shipping Country?
My Answer:
You can achieve this by adding a conditional check in the filter function. Here's an example code snippet:
php
add_filter('woocommerce_checkout_get_value', 'custom_checkout_get_value', 10, 2);
function custom_checkout_get_value($value, $input) {
// Enable autocomplete for specific fields
$allowed_fields = array('billing_country', 'shipping_country');
if (in_array($input, $allowed_fields)) {
return $value;
} else {
return '';
}
}
In the above code, we added a conditional check to only allow autocomplete for the 'billing_country' and 'shipping_country' fields. For all other fields, autocomplete will be disabled.
Rate this post
5 of 5 based on 5467 votesComments