问题
In Woocommerce i am trying to clear the checkout fields. so when a user that has ordered something before, and is now ordering something again, he/she will have to write in all his/her information again.
i am using this code
function clear_checkout_fields($input){
return '';
}
add_filter( 'woocommerce_checkout_get_value' , 'clear_checkout_fields' , 1);
Now this code is clearing all the fields, but it also changes my VAT to show as 0.
does anyone know a solution to this?
回答1:
There is some arguments errors in your woocommerce_checkout_get_value
hooked function.
There is in fact 2 arguments:
- the
$value
argument that is returned as it is a filter hook, - the
$imput
argument that you can use to target any checkout field.
So in your case you will use the $imput
argument, to avoid your custom VAT checkout field to be emptied. In the code bellow, you will need to replace vat_number
by the correct field name
attribute that is set in your custom VAT checkout field:
add_filter( 'woocommerce_checkout_get_value' , 'clear_checkout_fields' , 10, 2 );
function clear_checkout_fields( $value, $input ){
if( $input != 'vat_number' )
$value = '';
return $value;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
来源:https://stackoverflow.com/questions/50795010/clear-only-some-checkout-fields-values-in-woocommerce