WooCommerce: Limit State Dropdowns to One State Only

This is a workaround to Limit Shipping and Billing to One State Only. In two of my previous posts (Limit Shipping to One State Only and Limit Billing to One State Only) we’ve seen similar functionalities. In this case, let’s imagine we want to avoid that the user selects unwanted states.

Remove Unwanted States from the Dropdowns (including the “shipping calculator”) – WooCommerce

WooCommerce State Dropdowns @ Checkout
WooCommerce State Dropdowns @ Checkout
WooCommerce State Dropdown @ Cart Shipping Calculator
WooCommerce State Dropdown @ Cart Shipping Calculator

Limit State Dropdowns to One State Only – WooCommerce


// Only one state e.g. PA in US

add_filter( 'woocommerce_states', 'bbloomer_custom_woocommerce_states' );

function bbloomer_custom_woocommerce_states( $states ) {
$states['US'] = array(
'PA' => 'Pennsylvania',
);
return $states;
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

8 thoughts on “WooCommerce: Limit State Dropdowns to One State Only

  1. […] widely requested by many readers, clients and WooCommerce fans. We already saw in the past how to Limit State Dropdowns to One State Only (for both Shipping & Billing) and How to Sell to one State only […]

  2. Hi,

    I’ve read your limiting shipping, limiting billing, and limiting dropdown posts but still need some help.

    I want to limit shipping to only PA but allow billing from anywhere. I want to see just PA in the shipping dropdown but all the states in the billing dropdown.

    Are you able to help with this?

    Thanks for any advice!

    1. Laurie, thanks for your comment 🙂 I’ve seen you read all my articles about this, but doesn’t this -> https://businessbloomer.com/woocommerce-limit-shipping-one-state limit states for shipping only? Let me know – otherwise I’ll make sure to fix it 🙂

    2. Hi! It limits the state meaning the user will get an error if they try to use a non-permitted state but the state still shows up in the drop down.

    3. Hey Laurie, thanks for your message! Actually, this snippet should only show one state in the dropdown, so you can’t use a non permitted state 🙂 Do you have a screenshot for me, and have you edited the snippet?

    4. Hi!
      That is exactly the problem.

      It limits the states shown in shipping AND billing. I want every single state shown and active in billing and only certain states shown in shipping.

      Is that possible?

      I don’t see a place to attach a screen shot here. It would show that my billing and shipping drop downs both only show limited states.

      Thank you so much for your patience and help on this matter. I know a lot of other people have the same question.

    5. Thank you Laurie for following up 🙂 Yes, you’re right, this snippet of course targets both Billing and Shipping. I did further research yesterday but could not find a “conditional tag” to execute this filter on the shipping section only.

      I also did look on Google and no one has found a solution to this yet. I hope to be the first 🙂 I’ll keep you posted.

    6. Laurie, a little late but we finally found a working solution. Please check this new blog post here: https://businessbloomer.com/woocommerce-allow-shipping-one-state-only/. Hope this helps 🙂

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.