Woocommerce – disabling address fields on checkout based on dropdown states

I’ve been working recently on a way to disable the billing address in the checkout page of woocommerce when states in not equal to ‘Lima y Callao’

This is what i got for now

    jQuery(document).ready(function($){
$('#billing_state').change(function (){
 if($('#billing_state').val() == 'Lima y Callao'){
            if($('#billing_address_1').prop( "disabled", true )){
            $('#billing_address_1').prop( "disabled", false );
            }
                if($('#billing_address_2').prop( "disabled", true )){
            $('#billing_address_2').prop( "disabled", false );
            }   
    } else {
            $('#billing_address_1').attr('disabled', 'disabled').val('');
            $("#billing_address_2").attr('disabled', 'disabled').val('');
            $(this).removeClass("validate-required");
            $(this).removeClass("woocommerce-validated");
            if(!$(this).hasClass("validate-required")) {
            $(this).addClass("validate-required");
            }
            if(!$(this).hasClass("woocommerce-validated")) {
            $(this).addClass("woocommerce-validated");
            }        
          }
    }).trigger('change');
});

However, it only disables the textfields but doesnt enable when the option Lima y Callao is selected.
What do you think? I am already looking for answers and I’m trying my best to find a solution on my own.

Read more here: Woocommerce – disabling address fields on checkout based on dropdown states

Leave a Reply

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