Woocommerce: Hide Billing Address and Shipping Address when specific state is selected

I am trying to make the two textfields from billing_address and shipping address from the checkout hide and become NOT required when the selected option in state is not “Lima y Callao”. This is what I’ve been trying with no results.

if($("#billing_state option:selected").val() != "Lima y Callao"){

    $('#billing_address_1_field').hide(function(){
        $(this).removeClass("validate-required");
        $(this).removeClass("woocommerce-validated");
    });
    $('#billing_address_2_field').hide(function(){
        $(this).removeClass("validate-required");
        $(this).removeClass("woocommerce-validated");
    });
}

if($("#shipping_state option:selected").val() != "Lima y Callao"){

    $('#shipping_address_1_field').hide(function(){
        $(this).removeClass("validate-required");
        $(this).removeClass("woocommerce-validated");
    });
    $('#shipping_address_2_field').hide(function(){
        $(this).removeClass("validate-required");
        $(this).removeClass("woocommerce-validated");
    });
}

Read more here: Woocommerce: Hide Billing Address and Shipping Address when specific state is selected

Leave a Reply

Your email address will not be published. Required fields are marked *