How to limit shipping to specific states only in Woocommerce?

In this tutorial we’ll learn how to restrict shipping to specific states in Woocommerce. By default customer have all the state options where they can ship to.

To do this add the following lines of code at the end of your theme’s functions.php file:

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );

function custom_woocommerce_states( $states ) {

$states['US'] = array(

'PA' => __( 'Pennsylvania', 'woocommerce' ),

'CA' => __( 'California', 'woocommerce' ),

'FL' => __( 'Florida', 'woocommerce' ),

'MD' => __( 'Maryland', 'woocommerce' )

);

return $states;

}

You can easily add or remove states in the code.

Now do the following steps:

Add product to cart and move to cart page

woocommerce

Now proceed to checkout.

woocommerce

Here on the checkout page if you select any state that is not listed in the code then you’ll receive an error.

woocommerce

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

Leave a Comment

Your email address will not be published. Required fields are marked *