Help Wordpress

Help 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:

Best image optimizer wordpress

Best image optimizer wordpress

For good speed results of your website without doubt, very important optimize images. Loading image 200 kb – is not the same as loading image 100 kb. Seems [...]
What’s New in WordPress 4.9

What’s New in WordPress 4.9

On November 15, 2017, WordPress Version 4.9, named “Tipton” in honor of jazz musician and band leader Billy Tipton, is available for download or update in your WordPress [...]

Leave a Reply

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