Clear only some checkout fields values in Woocommerce

前端 未结 1 1778
[愿得一人]
[愿得一人] 2021-01-21 04:48

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

相关标签:
1条回答
  • 2021-01-21 04:59

    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 below, 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.

    0 讨论(0)
提交回复
热议问题