Force WooCommerce sells and ships ONLY one state

How do I force WooCommerce to sell and send only one state? I can select a country, but I cannot find a way to allow sale and delivery to only one country / region.

Let's say I only chose Canada and I only want to sell in Ontario. How can I achieve this? I should probably add something to the .php function to filter states, but I don't know where to look for it ...

Thank!

+3


source to share


1 answer


I found this solution, but probably 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;
}

      

+3


source







All Articles