Make field required based on an option

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #105372
    Mark
    Guest

    Hi there,

    Is it possible to make the EU VAT field required after selecting an option in a selectbox? My code right now is:

    function change_billingcompany_vatnumber($fields) {
        if ($_POST['afreg_select_user_role'] === 'wholesale_customer') {
            $fields['billing']['billing_company']['required'] = true;
            $fields['billing']['billing_eu_vat_number']['required'] = true;
        } else {
            $fields['billing']['billing_company']['required'] = false;
            $fields['billing']['billing_eu_vat_number']['required'] = false;
        }
        return $fields;
    }
    add_filter('woocommerce_checkout_fields', 'change_billingcompany_vatnumber', 20);
    

    Thanks!

    • This topic was modified 1 year, 1 month ago by Omar Dabbas.
    #105373
    WPWhale
    Moderator

    Hi Mark,

    Sorry for the delayed response, I missed this post by mistake.

    I suggest you try woocommerce_after_checkout_validation, and if that didn’t work, please reach us with wp-admin & FTP access at [email protected] and we will be glad to get this sorted.

    Omar

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.