Woocommerce – Jquery | Remove the required attribute from some checkout input fields based on the selection from a select field

Question

Hi everyone I’m working on the code of a plugin that I downloaded, the goal is to hide some fields of the Woocommerce billing checkout form based on the selection of a select by the user, the developer who created this plugin implemented an optional field named: billing_invoice_type, and then an if loop where it admits the various possibilities that when this field is equal to a value, something must be generated, at this point I have implemented the instructions to be able to hide the fields that interest me:

var wcpdf_IT;
function wcpdf_IT_billing_customer_type_change(wcpdf_IT_country_selected) {
    jQuery("#billing_cf_field label").html(wcpdf_IT.lblCommon);
    jQuery("#billing_cf").attr("placeholder", wcpdf_IT.txtCommon);
    if(jQuery("#billing_invoice_type").val() === "receipt" ) {

        // RIMUOVI LABEL E CAMPO INPUT | NOME DELLA SOCIETÀ
        jQuery("#billing_company_field ").hide();

        // RIMUOVI LABEL E CAMPO INPUT | CAP
        jQuery("#billing_postcode_field ").hide();

        // RIMUOVI LABEL E CAMPO INPUT | INDIRIZZO
        jQuery("#billing_address_1_field ").hide();

        // RIMUOVI LABEL E CAMPO INPUT | APPARTAMENTO / SUITE
        jQuery("#billing_address_2_field ").hide();

        // RIMUOVI LABEL E CAMPO INPUT | CITTÀ
        jQuery("#billing_city_field ").show();
        $('#billing_city').removeClass('woocommerce-invalid woocommerce-invalid-required-field');


        // RIMUOVI LABEL E CAMPO INPUT | PROVINCIA
        jQuery("#billing_state_field ").hide();


        jQuery("#billing_cf_field label").html(wcpdf_IT.lblPersonal);
        jQuery("#billing_cf").attr("placeholder", wcpdf_IT.txtPersonal);
    }
    wcpdf_IT_check_PEC();
}

now, however, the problem is not only to make them appear or hide, but that these default fields are of the required type, so the user during the compilation phase does not see them, but when he completes his compilation an error is shown on the display because he must fill in the hidden fields, so I have to remove the required attribute.

I tried in several ways through Jquery has removed the required attribute from the field that interests me but with failed attempts.

How can I do?

0
, user12584320 2 years 2020-01-03T08:38:59-05:00 0 Answers 87 views 0

Leave an answer

Browse
Browse