Make checkout fields required in Woocommerce checkout

后端 未结 1 647
谎友^
谎友^ 2020-12-20 23:18

For some reason, all the fields in Billing Address are marked as optional - customers are leaving the billing address fields blank and then their payments are being rejected

相关标签:
1条回答
  • 2020-12-20 23:42

    What you can do if you don't find the guilty as explained on my comment is to use the following (using here a highest hook priority if some other code is already using those hooks):

    add_filter( 'woocommerce_default_address_fields', 'customising_checkout_fields', 1000, 1 );
    function customising_checkout_fields( $address_fields ) {
        $address_fields['first_name']['required'] = true;
        $address_fields['last_name']['required'] = true;
        $address_fields['company']['required'] = true;
        $address_fields['country']['required'] = true;
        $address_fields['city']['required'] = true;
        $address_fields['state']['required'] = true;
        $address_fields['postcode']['required'] = true;
    
        return $address_fields;
    }
    

    Code goes in function.php file of your active child theme (or active theme). tested and works.

    For billing phone and email you can try

    add_filter('woocommerce_billing_fields', 'custom_billing_fields', 1000, 1);
    function custom_billing_fields( $fields ) {
        $fields['billing_email']['required'] = true;
        $fields['billing_phone']['required'] = true;
    
        return $fields;
    }
    

    or

    add_filter('woocommerce_checkout_fields', 'custom_billing_fields', 1000, 1);
    function custom_billing_fields( $fields ) {
        $fields['billing']['billing_email']['required'] = true;
        $fields['billing']['billing_phone']['required'] = true;
    
        return $fields;
    }
    
    0 讨论(0)
提交回复
热议问题