[WC] Force Ssn and Vat for billing and shipping to be required

Hi,

Add the following code at the end of the file functions.php located under the wp-content/themes/[themename]/

 

 

/**
 * Yit Force Billing & Shipping ssn and vat to be required
 *
 * @param  array $fields The checkout fields
 * @return mixed         The checout fields filtered
 */
function yit_force_vat_ssn_as_required( $fields ) {
    $keys = array(
        'billing', 'shipping'
    );

    foreach( $keys as $field ) {
        if ( isset( $fields[ "{$field}_vat" ] ) ) {
            $fields[ "{$field}_vat" ]['required'] = true;
        }

        if ( isset( $fields[ "{$field}_ssn" ] ) ) {
            $fields[ "{$field}_ssn" ]['required'] = true;
        }
    }

    return $fields;
}
add_filter( 'woocommerce_billing_fields',     'yit_force_vat_ssn_as_required', 11 );
add_filter( 'woocommerce_shipping_fields', 'yit_force_vat_ssn_as_required', 11 );

 

Tested with Bishop and Mindig. If this doesn't work on some other theme, please leave a reply and we will help you.

 

Was this article helpful?
7 out of 7 found this helpful

Back to Help Center

Powered by Zendesk