I'm trying to set up default variable value in woocommerce checkout page
$fields['address_1']['default'] = $cart_item['address'];
It works well only first time customer makes an order, when other order in process browser data is pre-filling fields, so i have used this
add_filter('woocommerce_checkout_get_value','__return_empty_string', 0, 0);
This filter returns with empty fields, but default value also returned empty.
You can try use instead:
add_filter( 'woocommerce_checkout_get_value', 'clear_shipping_fields_values', 5, 2 );
function clear_shipping_fields_values( $value, $input ) {
$items = WC()->cart->get_cart();
$item = reset( $items );
if( is_checkout() && isset($item['address']) && in_array( $input, ['billing_address_1', 'shipping_address_1']) ) {
$value = $item['address'];
}
return $value;
}
Code goes in functions.php file of your active child theme (or active theme). It should work.