Just over a year ago I wrote a post which shows how to disable free shipping on a per product basis. That’s really useful for stores that like offering free shipping on just about everything everything and want to disable it one or two items. But what about people in the opposite situation? You might have one or two really tiny items like bookmarks don’t want to charge people $5 for flat rate shipping.
I figured it was time to revisit this and write a snippet that helps these people out. We can use the shipping classes built into WooCommerce combined with just a couple lines of code to make it really easy to mark any number of products eligible for free shipping.
Create the Shipping Class
The first thing we have to do is create a shipping class. Go to Products > Shipping Classes. Add the name
Free Shipping, leave the rest of the fields blank, and press
Add New Shipping Class.
Now we’re going to to make sure the taxonomy slug was created correctly. Don’t worry – you don’t need to know what that is just that it was created correctly. It’s what we’ll use in our code to identify the correct shipping class.
Take a look at the existing shipping classes and make sure your class has the slug
free-shipping. If it doesn’t that’s OK just keep it in mind when we add the code. You’ll have to change one line.
Add the Shipping Class to Your Product
Before we jump into the code make sure you add the shipping class to your product. You can do this on the edit product page in the Product data panel under the shipping tab.
Add the Magic Code
We’ve created a shipping class that marks a product available to use Free Shipping and we’ve added that to a product. Now we need to write the code that does all the heavy lifting.
You can download this plugin, unzip it, and upload it to your site.
If your taxonomy slug isn’t
free-shipping and is
free-shipping-2 or something like that you’ll want to replace the default slug with your slug on the
$eligible = array( ‘free-shipping’ ); line.
Now anytime you have an order filled with products with this shipping class you should see the Free Shipping method. This snippet doesn’t affect your other free shipping settings. Ex. if you have a minimum order amount you’ll still need to meet that amount.
Image credit: Giphy