I came across with this How to blank all WooCommerce checkout fields by default except country? similar question which has an answer code that meet my needs, but this code will blank all woocommerce shipping and also billing checkout field when customer click checkout button.
if I want the shipping fields only to be blank, how the code will looks like?
Advertisement
Answer
To blank all WooCommerce shipping checkout fields, you will use the following:
add_filter('woocommerce_checkout_get_value', 'checkout_get_value_filter', 10, 2 ); function checkout_get_value_filter( $value, $input ) { if ( strpos($input, "shipping_") === 0 ) { return ''; } return $value; }
Or also this specifying each related shipping field key:
add_filter('woocommerce_checkout_get_value', 'checkout_get_value_filter', 10, 2 ); function checkout_get_value_filter( $value, $input ) { $key_fields = array( 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_country', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_country', 'shipping_state', 'shipping_postcode', ); if ( in_array($input, $key_fields) ) { return ''; } return $value; }
Code goes on functions.php file of your active child theme (or active theme). It should works.