Limit which States Woocommerce will Ship to (for Free!)
Note that I am not referring to “free shipping” here in any way, but rather that you can achieve limiting which states a product can ship to from any shipping method without paying for a plugin to do so.
If you’re comfortable editing your theme files, and either have a custom theme or a child theme already setup, you can add the following code to your functions.php file, to only allow the states which you include in the function.
This alleviates buying an expensive plugin with just a little code work on your paste.
// only ship to certain states
add_filter( 'woocommerce_states', 'limit_woocommerce_states' );
function limit_woocommerce_states( $states ) {
$states['US'] = array(
'AL' => __( 'Alabama', 'woocommerce' ),
'AK' => __( 'Alaska', 'woocommerce' ),
'AZ' => __( 'Arizona', 'woocommerce' ),
'AR' => __( 'Arkansas', 'woocommerce' ),
'CA' => __( 'California', 'woocommerce' ),
'CO' => __( 'Colorado', 'woocommerce' ),
'CT' => __( 'Connecticut', 'woocommerce' ),
'DE' => __( 'Delaware', 'woocommerce' ),
'FL' => __( 'Florida', 'woocommerce' ),
'GA' => __( 'Georgia', 'woocommerce' ),
'HI' => __( 'Hawaii', 'woocommerce' ),
'ID' => __( 'Idaho', 'woocommerce' ),
'IL' => __( 'Illinois', 'woocommerce' ),
'IN' => __( 'Indiana', 'woocommerce' ),
'IA' => __( 'Iowa', 'woocommerce' ),
'KS' => __( 'Kansas', 'woocommerce' ),
'KY' => __( 'Kentucky', 'woocommerce' ),
'LA' => __( 'Louisiana', 'woocommerce' ),
'ME' => __( 'Maine', 'woocommerce' ),
'MD' => __( 'Maryland', 'woocommerce' ),
'MA' => __( 'Massachusetts', 'woocommerce' ),
'MI' => __( 'Michigan', 'woocommerce' ),
'MN' => __( 'Minnesota', 'woocommerce' ),
'MS' => __( 'Mississippi', 'woocommerce' ),
'MO' => __( 'Missouri', 'woocommerce' ),
'MT' => __( 'Montana', 'woocommerce' ),
'NE' => __( 'Nebraska', 'woocommerce' ),
'NV' => __( 'Nevada', 'woocommerce' ),
'NH' => __( 'New Hampshire', 'woocommerce' ),
'NJ' => __( 'New Jersey', 'woocommerce' ),
'NM' => __( 'New Mexico', 'woocommerce' ),
'NY' => __( 'New York', 'woocommerce' ),
'NC' => __( 'North Carolina', 'woocommerce' ),
'ND' => __( 'North Dakota', 'woocommerce' ),
'OH' => __( 'Ohio', 'woocommerce' ),
'OK' => __( 'Oklahoma', 'woocommerce' ),
'OR' => __( 'Oregon', 'woocommerce' ),
'PA' => __( 'Pennsylvania', 'woocommerce' ),
'RI' => __( 'Rhode Island', 'woocommerce' ),
'SC' => __( 'South Carolina', 'woocommerce' ),
'SD' => __( 'South Dakota', 'woocommerce' ),
'TN' => __( 'Tennessee', 'woocommerce' ),
'TX' => __( 'Texas', 'woocommerce' ),
'UT' => __( 'Utah', 'woocommerce' ),
'VT' => __( 'Vermont', 'woocommerce' ),
'VA' => __( 'Virginia', 'woocommerce' ),
'WA' => __( 'Washington', 'woocommerce' ),
'WV' => __( 'West Virginia', 'woocommerce' ),
'WI' => __( 'Wisconsin', 'woocommerce' ),
'WY' => __( 'Wyoming', 'woocommerce' )
);
return $states;
}
Just remove any states you don’t wish to include, and they’ll no longer show up in the dropdown when a user goes to checkout. You’d likely want to make a note of this elsewhere on your site, for example at the top of the checkout, cart or single product pages.
Up Next: The Simplest Case for Why You Should Never Use a Site Builder