将帐单Woocommerce的Jquery从必填更改为不需要

问题描述 投票:0回答:1

hi,我通过jquery修改了插件的代码,以使输入字段根据选择字段的选择而显示和隐藏,代码正常工作,我在下面进行报告。

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 ").hide();

        // 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();
}

这些未显示的输入字段是必需的,因此,当用户看不到它们并编译其余字段并按send时,将出现所需属性的编译警报,我想附加一个jquery声明删除必需属性的语句。

我知道Woocommerce文档通过此php指令通过构建插件或在functions.php文件中实现代码提供了可能性:

add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
function wc_npr_filter_phone( $address_fields ) {
    $address_fields['billing_postcode']['required'] = false;
    return $address_fields;
}

但是我需要从Jquery中删除必需的,同样是因为使用php,它将完全消除它,因此会禁止用户选择

php jquery wordpress
1个回答
0
投票

例如,您可以在隐藏元素的同时清除required属性

jQuery("#billing_company_field ").hide().prop('required', false);

或者,您可以通过禁用输入来有效地删除输入:

jQuery("#billing_company_field ").hide().prop('disabled', true);
© www.soinside.com 2019 - 2024. All rights reserved.