Helper Wordpress

Helper Wordpress

Wordpress can be fast. Very fast. Really :)

Woocommerce exclude states – free plugin

Woocommerce exclude states – free plugin

Sometimes becomes necessary to exclude some U.S. states on the Woocommerce checkout page. The reasons may be different – for example store owner not want to deliver goods in the particular states. Or in another case it can be conversely – such as the store works only with a few specific U.S. states. In this article I will demonstrate few simple ways do it: via code snippets or via my free plugin (WooCommerce Exclude States).
So, how add/exclude U.S. states in WooCommerce? Presently I know about three ways. In this article will describe each of them, and you yourself will choose the best way.

Exclude U.S. states in WooCommerce via translation file

The list of the U.S. states located in /wp-content/plugins/woocommerce/i18n/states/US.php file.
But this decision has a significant drawback. From time to time you need update WooCommerce and after update, you will must to edit this file again.

Exclude U.S. states in WooCommerce via functions.php

If you dont like too much plugins on your site and on condition that you know PHP, this way without a doubt will be the best. Just add in the functions.php file of your theme the following code snippet:

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
function custom_woocommerce_states( $states ) {
$states['XX'] = array(
'XX1' => 'State 1',
'XX2' => 'State 2'
return $states;

Without a doubt, this solution is also have drawbacks:
1 – when you will update the template, you will need to re-edit the functions.php;
2 – if you decide to change the template, you have to make accordingly changes in functions.php of new template;

Woocommerce exclude states, free plugin

Given these points, I create a simple free plugin for Woocommerce. It allows you to add and exclude U.S. states. And compared to first and second ways, dont need any changes after update WooCommerce or your WordPress theme.

1. Upload the plugin files to the /wp-content/plugins/woocommerce-exclude-states directory;
2. Activate the plugin through the ‘Plugins’ screen in WordPress;
3. Use the WooCommerce -> Edit U.S. states menu and enable or disable U.S. states;

As you can be seen on screenshots bellow, the plugin very easy to use, but if you have any questions you can ask in comments.

Backend screenshot - Woocommerce exclude states
Backend screenshot – Woocommerce exclude states
Frontend screenshot - Woocommerce exclude states
Frontend screenshot – Woocommerce exclude states

For advansed users current version have 2 hooks: woocommerce_update_states_hook and woocommerce_default_states_hook, and you can use it for more flex. For example, simple snippet:

add_action( 'woocommerce_update_states_hook', 'my_update_function' );
function my_update_function(){
//your code


Most important Changes in this version:

1 – Of course, it full compatibility with current version of WordPress and WooCommerce;
2 – Hooks for events (update/reset buttons);

All changes you can see in readme.txt (section Changelog).

Woocommerce exclude states: download last version. Also you can download my other plugins or hired me for create specific plugin on Upwork. And as has been noted, any questions or any ideas – welcome to comments.

If you like this plugin, please click on one of the buttons to share it with your friends. Thank you!

Related posts:

Lazy Load Google Maps

Lazy Load Google Maps

Lazy Load Google Maps will improve the performance of your initial page load, especially if there are two or more maps embedded on the same page. I think, [...]
Good, fast, cheap. Pick two.

Good, fast, cheap. Pick two.

You’ve probably know the phrase: “Good fast cheap. Pick two”. This concept has a few different names: it’s known as the Triple Constraint, Iron Triangle but most popular [...]
What’s New in WordPress 5.1

What’s New in WordPress 5.1

WordPress 5.1 available on February 21, 2019. It have name “Betty” in honoring American jazz singer Betty Carter. WordPress 5.0 had been downloaded more than 35 million times [...]

Leave a Reply

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