Sell in specific States/Provinces/Regions with WooCommerce


As you know, WooCommerce allows you to sell only in specific countries, like only in Italy or in Unites States.
What if you want to sell only in a specific province, or only in California for example?

There’s a little snippet of code to add to your site. In this example i want to sell only in California so i need to update the states dropdown in the checkout page to include only that state.

To do so, open your functions.php file located in wp-content/themes/your-theme-name/ and add this code at the end of the file:

Delete the <?php first line if you are having errors come up after saving the file.*

Done! Now you will see only California in the states dropdown on your checkout page.

If you need a list of all the states/regions/provinces/counties available in WooCommerce, you can find them in wp-content/plugins/woocommerce/i18n/states/.

20 replies
  1. Adeel
    Adeel says:

    Hi Nicola ,

    Hope you are doing well .

    I have read you post which is very helpful for me to sell the products in specific region but now i want to sell the products through the zip codes and only allow the desire zip code to purchase the product rest of the zip codes are restricted to buy. Also i want to set the different pricing for the specific zip codes.

    Please suggest me any extension if available their OR do some code amendments to achieve the task.

    I will rewards you the bundle of coffee dont worry about that bro 🙂 .

    Thank you very much !

    Best regards,

    • Nicola Mustone
      Nicola Mustone says:

      Hi Adeel,
      i would suggest to use Table Rate Shipping:

      With it you can specify shipping rules based on the zip code. If the customer’s zip code is not allowed, he will not be able to purchase because there won’t be a shipping method available.

      For the prices based on the zip code, i don’t think there’s a plugin for this, and also i don’t think it could work properly.
      The zip code is only checked on the checkout page, so you should change the prices there. Will the customer see this change on the checkout page?

      I don’t think so, and you will receive a lot of messages about it.
      Anyway, i’m sorry but i don’t have a code or a plugin for this.

  2. Nicola Mustone
    Nicola Mustone says:

    you don’t need my code to sell in a specific country. You can limit the countries where you sell from the settings in WooCommerce > Settings > General!

    • Nicola Mustone
      Nicola Mustone says:

      Sorry but a screenshot of what? It does not change anything visible. You will still see the default WooCommerce checkout page, only the states dropdown will have less options to choose from.

    • Nicola Mustone
      Nicola Mustone says:

      You need to change $states['US'] to $states['CA'] and then list all the provinces you want to show. You can get the list of Canada’s provinces from the file CA.php located in wp-content/plugins/woocommerce/i18n/states/.

  3. mai
    mai says:

    Thank u for the code

    Please what if I have some products that can only be deleivered localy, but we sell other products all over the world.
    What is a way to restrict these products to ONE contry only , not restric all my store and its products (countries settings in woocomerce general)

    for example, flower and chocolate, i only want to sell it locally

    but i want that before the checkout page, as it will take customer time to write everything and then he sees he cnat order

    like amazon tells u they cant ship to this address in the very last step

    thank u
    waiting ur replay

  4. Justin Pratscher
    Justin Pratscher says:

    Hi. This works great, but I was wondering if you know of a solution that would allow me to adjust only the shipping address states, leaving the billing address states in tact.


  5. ryan
    ryan says:

    Hi, Nicola great code I’m getting errors when adding more than one state. I’m not closing or opening at the right time between parts of the array? Could you add a snippet of more than one state for syntax clarity?

  6. Vytis
    Vytis says:

    Great code, but is there any way to restrict based on shipping class or category? Your code is nearly perfect for my needs.

  7. Sam
    Sam says:

    Restrict based on shipping and not both billing and shipping?

    Say I restrict shipping to Alaska. I still want someone from Alaska to be able to buy it and ship to a state that’s not restricted.

  8. Adrian
    Adrian says:

    Hey Nicola! Great code. thanks for sharing. There is one thing I wonder if you have a solution. I have a product which I am selling to Dublin, Ireland. But within Dublin, for some zones like D1 to D10 I want that the shipping is free shipping and for other zones there will be shipping cost.

    I hope my question is clear to you. If you could help me out, it will be a great pleasure for me.



Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply