Force WooCommerce to sell and ship to ONLY one state

How do I force WooCommerce to sell and ship to only one state?
I can select a country but I can’t find any way to allow selling and shipping only to one state/region.

Let’s say I’ve selected only Canada and I want to sell only in Ontario. How can I achieve that? I probably have to add something to function.php to filter the states, but I don’t know where to look for it…

Read More

Thanks!

Related posts

Leave a Reply

1 comment

  1. I’ve found this solution, but probably it’s not the “cleanest” way to achieve this.

    Any suggestion?

    add_filter( 'default_checkout_country', 'change_default_checkout_country' );
    add_filter( 'default_checkout_state', 'change_default_checkout_state' );
    
    function change_default_checkout_country() {
      return 'CA'; // country code
    }
    
    function change_default_checkout_state() {
      return 'ON'; // state code
    }
    
    
    add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
    
    function custom_woocommerce_states( $states ) {
      $states['CA'] = array(
        'ON' => 'Ontario',
      );
      return $states;
    }