Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • I am going the other way – so I have fields defaulted to required on a registration and when a checkbox is clicked to reuse billing data for a registration I hide the registration fields and would then like to make them un-required. My short term fix was to just fill in dummy data to allow the user to submit. Clunky but got me a near term answer. So while I would like to turn it off I think I will likely instead just do a copy of the form data to fill in instead of hiding the form fields.

    I am old school and it bothers me to store/pass extra data instead of just the duplicate flag to my customer database. So your solution to implement a client side check and not use the Woo required flag is one solution. Another thought would be to do an Ajax call to a server side function but I have not seen a good action function in Woo to do this.

    Thanks for sharing.

    • This reply was modified 6 years, 4 months ago by dirkjungquist.

    I am looking for the same answer – how to set/unset the required attribute. I found an example that claims to do this:

    https://stackoverflow.com/questions/55206672/make-woocommerce-checkout-phone-field-optional-based-on-shipping-country/55209546#55209546

    The core of this is the function:

    function actionRequire( actionToDo=’yes’, selector=” ){
    if ( actionToDo == ‘yes’ ) {
    $(selector).addClass(“validate-required”);
    $(selector+’ label > .required’).remove();
    $(selector+’ label’).append(required);
    } else {
    $(selector).removeClass(“validate-required”);
    $(selector+’ label > .required’).remove();
    }
    $(selector).removeClass(“woocommerce-validated”);
    $(selector).removeClass(“woocommerce-invalid woocommerce-invalid-required-field”);
    }

    I have tried this and the field label has the required “*” removed but this appears to be cosmetic and the reemoveClass did not actually make the field un-required in my tests.

    So I am still looking for how to change the required attribute dynamically.

Viewing 2 replies - 1 through 2 (of 2 total)