4

I've created several new checkout fields for my checkout page.
One field is the first radio button with "type klant" this lets the user choose between customer type (business or private). When either is selected, some fields are hidden/shown by me with Javascript.

The "bedrijfsnaam" (business name) field is shown when "bedrijf" (business) is selected, it is not required. If made required and the user selects "particulier" (private) the field is not hidden with js, but present html-wise, so when completing, the validation gives an error to enter the business name.

How can I change the validation to only check the business name field when business is selected in customer type?

I probably have to do something with the do_action( 'woocommerce_before_checkout_process' ); to make the required check based on the radio button, but I got stuck there, any clues?

Thanks!

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Boris Kamp
  • 341
  • 1
  • 6
  • 16

1 Answers1

-2

Suggesting you a better plugin for this:

https://wordpress.org/plugins/woo-checkout-field-editor-pro/

You can add multiple checkout fields and make them required. Also you can change lables of existing fields.

enter image description here

Maha Dev
  • 3,915
  • 2
  • 31
  • 50
  • Thanks for the suggestion Maha! I looked at this plugin and did not find the option to make a field's required boolean dependent on another field value, am I right? – Boris Kamp Apr 21 '16 at 18:55
  • 1
    Thanks Maha, but this is not what I'm trying to achieve, I need to make it conditional.... All the stuff the plugin you mentioned does, I already did myself by adding code to my functions.php. please read my initial question again – Boris Kamp Apr 23 '16 at 15:48
  • This just doesn't answer to the OP question. Related: https://stackoverflow.com/a/57148040/2394994 – Marcio Duarte Sep 19 '19 at 21:18