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 [...]

4 Replies to “Woocommerce exclude states – free plugin”

  1. Hi! I sent a contact message, but I’m not sure if it is the right place, so here I am in the comments. 😉

    After I upload and activate the WooCommerce Exclude Plugin it looks absolutely great with a wonderfully easy interface, 🙂 (Thank you for keeping the interface simple!) however, when I click the Save State List button or Cancel button, a 403 forbidden error will always pop up. There is nowhere else on the site where this is happening, so I know it is all about this plugin.

    I went into my backend and changed the permissions of the WooCommerce Exclude Plugin to 755 and 644. This didn’t work, but it was interesting that I had to do this. I am looking around for the .htaccess file, because I’ve read that this might be the problem.

    I am almost entirely new to website use, and so I was wondering if you would happen to know of something very obvious I should be doing, like with permalinks or caching, that as a newbie I haven’t thought to do, and which would be something an expert would take for granted that I would do?

    Any advice would be greatly appreciated! =D I know that this plugin will work great if I can only figure out what on my end I’m doing wrong … , and it is an absolutely desirable plugin! =) Thank you for your time!

    1. Hi Aimee and thank you for your question. The WooCommerce Exclude Plugin don`t create any files, it mean don`t need change any permissions. Sure, 403 error mean access problem, but I think issue in WP roles. Try activate and save settings as admin.

Leave a Reply

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