Only Ship to Continental United States with WooCommerce

Continental United States

One of the most powerful plugins for WooCommerce is Table Rate Shipping because it’s so configurable. You can create your own rules for bulk shipping, weight based shipping, or set up shipping zones and charge different rates for each zone. When someone requests their existing shipping method only support certain zones, or charge extra for specific zones we usually point them to Table Rate Shipping because that extension can do just about anything.

It would be nice if we could take some of the functionality of that plugin out and apply it to other shipping methods (like UPS, FedEx, USPS, etc.) but at WooThemes we’re very aware of feature creep and if we added these other feature the existing shipping methods would be bloated to the point of being unusable. So without adding a whole bunch of options that most users don’t want the best way to do this is to write a snippet of code to do this.

Only Ship to Continental United States

I decided to dig in and create a mini plugin for users to which checks which state they are in and then disables all shipping methods if the user isn’t in the continental United States. I’m including the plugin for you to look at the code but you can also go the plugins home page and download it, extract the zip file, and upload the folder to your /wp-content/plugins/ directory of your site.

Shipping Hooks

I’ve been doing support for WooCommerce for just about 6 months now and it’s still amazing to me how easy it is to change something using the giant list of hooks we have. For shipping methods especially there’s the woocommerce_available_shipping_methods filter you can use to do modify them however you need.

Hopefully this plugin solves whatever needs you have and if not use that woocommerce_available_shipping_methods hook and happy coding! :)

Fields marked with a * are required

Want to have more awesome WooCommerce customizations, tips, & tutorials delivered straight to your inbox?

35 thoughts on “Only Ship to Continental United States with WooCommerce

  1. It looks like version: 2.0.20 changed the way shipping works?

    Does this code work with lastest version of Woocommerce?

    • Hi Michelle! I just tested this myself and it seems to work fine. There’s most likely another plugin doing something to mess this up. Disable all other plugins and see if it works with flat rate shipping. Then add the plugins back in one by one.

  2. Thank you sir! Just what I needed.

  3. Thank you, that’s exactly what I needed :) Cheers!

  4. Thanks for the info! Do you have any advice on how to restrict coupons to a specific country in Woocommerce?

  5. What about only accepting orders from a specific state? Is that do-able?

  6. Hi Patrick,

    This looks like an AWESOME plugin! It’s exactly what I’ve been looking for.

    Unfortunately, I downloaded, installed, and activated it yet it doesn’t seem to be working. Maybe the WooCommerce 2.1 update broke it? Is there any way you know to get it running again?

    Thanks!

    • I just tested it on my own test site and it works fine. I did replace the old filter, woocommerce_available_shipping_methods, with the new one, woocommerce_package_rates. That should only have printed a warning to the screen if WP_DEBUG was active and not caused any sort of error. Regardless, give the new one a try. If that doesn’t fix it there’s got to be some sort of conflict with a theme or plugin on your site.

  7. Thanks for the post! Table Rate Shipping doesn’t work at all with UPS, correct? I have an ecommerce site selling wine, so we are restricted from shipping to certain states (in the U.S.A.). I’d think Table Rate Shipping would be the best option for limiting certain states, but after using it, it seems to override UPS. Furthermore, I can’t even figure how to restrict shipping to certain states using TRS. Am I missing something?

    Thanks again!

    • You can use Table Rate Shipping to create shipping zones (where you may exclude certain states) but you have to create your own shipping methods for those shipping zones. You can’t use UPS shipping within Table Rate Shipping. You’d have to estimate UPS rates and set up your own rates.

      This really isn’t the right medium for this. For questions like this I highly recommend reaching out to WooThemes support (who knows I might even get the ticket!) and they can give you a much more in-depth answer.

  8. Thank you, is there a solution for excluding Alaska & Hawaii when using Table Rate Shipping?

    • If you’re using Table Rate Shipping you can create a shipping zone of the remaining 48 states without any code.

      • I have done this, but it isn’t eliminating Alaska, Hawaii, the Armed Force Options and Guam from the locations to ship to on the drop down.

        Any other suggestions?

        • This plugin won’t remove those options from the dropdown. That’s not a good user experience since the user will keep searching for it and get frustrated. It’s better to show them the option and then tell them there aren’t any shipping methods for that area. If you want to remove the options from the dropdown you’ll have to write a very different plugin.

  9. Hi Patrick,

    I can’t manage to get your plugin to work. I tried disabling all other plugins, but no luck.

    Not sure if you’re familiar with it, but I’m using the Avada theme (http://theme-fusion.com/avada/). They don’t have any instances of “woocommerce_available_shipping_methods”, “woocommerce_package_rates” in their theme.

    Any idea on what the problem is? Any help is much appreciated!

    • Hey Brandon,

      Either version of the plugin should work. The newest version, the one with woocommerce_package_rates , will make sure there are no warnings printed to the screen.

      Have you tried disabling the theme to see if that could be the cause?

      • Hey Patrick,

        I tried changing the theme, but it still doesn’t work for me even with default theme Twenty Fourteen v1.1. I don’t see any errors on the screen either way. I still see Alaska, Hawaii, Guam, etc. though.

        Thanks for responding so quickly. Hoping this clears things up. Please advise. Thanks in advance!

        • Hey Brandon – I edited your comment a bit for brevity. The issue here is that this plugin doesn’t remove those options from the dropdown. If someone selects that location they will get a message saying no shipping options are available. See this comment for why that’s a good idea.

  10. This is a nice catch-all, though I’m curious as to whether you’ve made it work per-product – if it could be an ‘on/off’, or ‘restrict shipping on this product’ or some such thing.

    • You can certainly extend this so it only applies to certain products. You’d want to add some extra conditional programming to the existing if statement. But depending on how you want this to work you may want to use Table Rate Shipping with shipping classes which is probably easier than writing the code.

  11. Great, easy to use plugin. Thank you!

  12. Hi!

    I’m wondering if there’s a way to restrict shipping of a category of products to one specific state. We run a liquor store, and while wine can be shipped to many different states, hard liquor can only be shipped within NY. Is there a way to restrict just that category of products?

    Thanks!

  13. Hey Patrick,
    I am wondering how hard it would be to make this so that when it returns false the Payment Options and Place Order button disappear. I just wonder how many users will actually notice that they’re not purchasing shipping when they still have the option to check out…

  14. I found an alternative that works if you only want to ship everything to the continental US, and just don’t want the other options listed as an option. Since it may work for others in a similar situation here it is (credit to http://www.terrytsang.com/tutorial/woocommerce/add-modify-states-for-woocommerce-checkout-form/)

  15. I installed your plugin, but it does not seem to be working. Our store is http://www.maineloghome.com

  16. Is there a way to assign this to work with only some shipping methods? Such as only restrict Flat Rate Shipping to the Lower 48, and all other shipping methods are allowed.

    Thanks!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>