WooCommerce conditional required checkout fields


I would like to change the required billing fields based on a custom filed that I’ve added:

add_action( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );

function custom_woocommerce_billing_fields($fields)
    $fields['my_options'] = array(
        'label' => __('Order as'),
        'required' => true,
        'type' => 'select',
        'options' => array(
            'person' => __('Person')            
            'company' => __('Company'),
        'priority' => 0

    $fields['billing_options'] = array(
        'label' => __('Tax Number'), 
        'required' => true, 
        'clear' => false, 
        'type' => 'text',
        'priority' => 31

    return $fields;

So if the user selects ‘Person’ in the drop down option I would like the:

  • company name,
  • ‘billing_options’

fileds to be no longer required.

And when ‘Company’ is selected the:

  • List item

Name and Surname
are not required but:

  • company name,
  • ‘billing_options’

are required.

So far I’ve been trying to use the woocommerce_checkout_process hook but without any luck. Can somebody please help?


>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/woocommerce-conditional-required-checkout-fields/">

WooCommerce conditional required checkout fields</a>
, Kanguros 8 months 0 Answers 56 views 0

Leave an answer