Sell to Specific States Woocommerce

In this post I am sharing WooCommerce code snippet that will allow you to restrict selling of products in a specific state(s) of a selected country. I am sharing two examples, one for United States and one for Australia.

Example 1: United States

The code snippet will allow you to sell to only three states; Florida, Indiana and Oklahoma.

add_filter( 'woocommerce_states', 'shyk_sell_specific_states' ); 
function shyk_sell_specific_states( $states ) { 
$states['US'] = array( 
'FL' => __( 'Florida', 'woocommerce' ), 
'IN' => __( 'Indiana', 'woocommerce' ), 
'OK' => __( 'Oklahoma', 'woocommerce' ), 
); 
return $states; 
} 

Example 2: Australia

The code snippet will allow you to sell only to customers of Queensland.

add_filter( 'woocommerce_states', 'shyk_sell_specific_states' ); 
function shyk_sell_specific_states( $states ) { 
$states['AU'] = array( 
'QLD' => __( 'Queensland', 'woocommerce' ), 
); 
return $states; 
} 

Also Read:

2 thoughts on “Sell to Specific States Woocommerce”

Leave a Reply

Your email address will not be published.