Patrick's Programming Blog

Enable Free Shipping on a Per Product Basis

  1. Blogging for Hippo
  2. Schedule Sales with WooCommerce
  3. The Problem with Focus
  4. Give Thanks
  5. Be Thankful for the People Who Inspire You
  6. Give Yourself Space
  7. Build Resources From Support
  8. How Hard Can Membership Be?
  9. Adding Social Media Icons to WooCommerce Product Pages
  10. How to Export WooCommerce Subscriptions
  11. Upgrade Your Contact Form With Ninja Forms
  12. Why I Write
  13. Blog Comments Policy
  14. Content Marketing Works – Even with Furnace Filters
  15. Making Email from Your Website More Reliable with Email Delivery Tools
  16. A Happiness Podcast?
  17. Podcast Compensation
  18. Wishlists Done Right
  19. Enable Free Shipping on a Per Product Basis
  20. Improve Your Writing with the Hemingway Editor
  21. Tell Users What You're Doing
  22. 2014 Business Review
  23. Mind Your Own Business
  24. Think Different to 10x Your Business
  25. Let Projects Die
  26. Maximize Your Creative Energy
  27. Use Git Bisect to Find Bugs in Your Codebase
  28. My Personal Value of Remote Work
  29. Don't Spam Email Receipts
  30. Make Your Own Luck
  31. Cold Showers and the Power of Challenges

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.

Copy the shipping class slug if it's different than free-shipping.

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.

Make sure you set mark your product as part of the free shipping class. You can mark as many products as you like this way.

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.

Happy shipping!

Image credit: Giphy

Exit mobile version