skip to Main Content

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?

2

Answers


  1. did you tried $('your_elem').removeAttr('required') ?

    This should work.

    Login or Signup to reply.
  2. I’m not sure if this will work for your case or not, but you can try it
    RIMUOVI LABEL E CAMPO INPUT | NOME DELLA SOCIETÀ

    jQuery("#billing_company_field").hide(function(){
    
        jQuery(this).removeClass("validate-required");
        jQuery(this).removeClass("woocommerce-validated");
        jQuery('#billing_company').val("no");
    
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search