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 custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

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. Follow @rmelogli

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? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

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