Offering world wide shipping is great of course, but not every product is allowed to ship world wide or maybe even nationally without a long process of paperwork (or even at all). Products like live stock, plants, alcoholics, medicins, weapons of any kind, hazardous materials etc.

Even if you’re just unable to ship to certain locations such as Hawaii or Alaska you’d want to inform your customers about this.

Its important that your WooCommerce store doesn’t allow users to checkout with these products in their cart to the prohibited locations. Telling customers in hindsight after completing and paying for their order you can’t ship to them is a big no-no.

Configuring Shipping Rates

If the only products you sell are limited to shipping to certain locations you can configure shipping rates in a way that no options are available to the limited locations. When WooCommerce does not have any shipping options available it won’t allow the customer to complete the order.

What are Shipping Validation Rules?

Shipping validation rules are not a official thing in WooCommerce. The shipping validation rules I’m talking about here are regular notices that show at the cart/checkout based on the cart contents / shipping location. Here’s an example of how the result will look like after following this post further.

The actual look and feel of the validation message depends on your theme, each WooCommerce theme should either take over the WooCommerce default notice styling or have their own style.

Configuring Shipping Validation Rules

However, if you have mixed products that are allowed to ship more widely and those that are limited you can configure shipping validation rules. Shipping validation rules are not something that is build in WooCommerce Core, but can be done through some code snippets, or if you prefer through a Shipping Validation plugin.

Prevent Shipping to Certain States

Using the following code snippet you can setup a shipping validation rule for specific states. The country is also checked to ensure the validation rule doesn’t show for other countries that may have the same state code.

Prevent Certain Products From Shipping to Certain States

The above code snippet prevents your entire store from shipping to the given state(s). The following code snippets allow you to target specific or groups of products. This can be based on product ID, category or shipping class.

Product ID

Product Category

Shipping Class
Shipping classes are very similar to categories from a technical point of view, so this code snippet is very similar to the categories one. A big difference is how it can be utilized in WooCommerce. E.g. you can setup a specific ‘limited’ shipping class and assign that to products over several categories.

Advanced Shipping Validation for WooCommerce

There’s also a Advanced Shipping Validation for WooCommerce plugin available that allows you to configure shipping validation rules through an interface. Using conditions you can configure (almost) everything we’ve done above through code snippets and more. Depending on your own requirements you can choose to use one of the code snippets or the plugin.

About the author: Jeroen Sormani is actively building WordPress, WooCommerce and Easy Digital Downloads plugins. Slightly obsessed by writing high quality code.
Follow Jeroen on Twitter

Leave a Reply

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