1

I would like to remove 3 Canadian Provinces from the Woocommerce Checkout page dropdown boxes, so those provinces cant be selected when ordering.

I found the answer for US States here on how to remove US states from the woocommerce checkout drop down boxes (code copied below):

    add_filter( 'woocommerce_states', 'custom_us_states', 10, 1 );
function custom_us_states( $states ) {
    $non_allowed_us_states = array( 'AK', 'HI', 'AA', 'AE', 'AP'); 

    // Loop through your non allowed us states and remove them
    foreach( $non_allowed_us_states as $state_code ) {
        if( isset($states['US'][$state_code]) )
            unset( $states['US'][$state_code] );
    }
    return $states;
}

I am wondering how to adjust this for Canadian Provinces?

The code for Canada is CA. The codes for the provinces I want to remove are:

  1. NU - Nunavut 2. NT - Northwest Territories 3. YT - Yukon Territory
yatgirl
  • 169
  • 3
  • 11

1 Answers1

2
add_filter( 'woocommerce_states', 'custom_ca_states', 10, 1 );
function custom_ca_states( $states ) {
    $non_allowed_ca_states = array( 'NU', 'NT', 'YT' ); 

    // Loop through your non allowed us states and remove them
    foreach( $non_allowed_ca_states as $state_code ) {
        if ( isset($states['CA'][$state_code]) ) {
            unset( $states['CA'][$state_code] );
        }
    }
    return $states;
}

Artemy Kaydash
  • 459
  • 5
  • 4
  • Thank you ! I thought I might have to put something different for provinces, but I guess not. Super ! – yatgirl Jul 21 '22 at 02:07