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
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;
}
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
WooCommerce: Cart and Checkout on the Same Page This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and…
WooCommerce: Redirect to Custom Thank you Page How can you redirect customers to a beautifully looking, custom, thank you page? Thankfully you can add some PHP code to your functions.php or install…
WooCommerce: Disable Payment Gateway by Country You might want to disable PayPal for non-local customers or enable a specific gateway for only one country… Either way, this is a very common…
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”
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.
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?
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.
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!
Gracias, me ha servido para límitar los estados de envío a Ciudad de México y Estado de México. Gracias¡¡¡¡
You’re welcome
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!
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 🙂
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.
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?
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.
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.
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 🙂