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; }
Can you help me with the snippet for Nigeria as the code is not working on my site
Send me an email to a.hassan@ahmadshyk.com with your requirements.