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 snippet?

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

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.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent 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.

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

  1. Gracias, me ha servido para límitar los estados de envío a Ciudad de México y Estado de México. Gracias¡¡¡¡

  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 🙂

      1. 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.

        1. 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?

          1. 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.

            1. 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.

            2. 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 shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

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