WooCommerce conditional required checkout fields

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744939426a4602231.html

相关推荐

  • WooCommerce conditional required checkout fields

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信