WooCommerce: Free Shipping on a Per Product Basis in the Same Cart

Remi | March 19, 2015 | in WooCommerce

This is a common request from WooCommerce users:

I want to ship specific products for free while some others will have shipping costs, but when a product having free shipping is in cart with another product that has shipping costs, free shipping isn’t available at all, what to do?

There’s a solution to that! And you don’t need any plugins to solve this issue. Based on a post by Mike Jolley, I’d like to explain how to use different shipping methods on a per product basis in the same cart. Let’s say you have two products, one that must be shipped for free, and a second one having a flat shipping cost (that would work with rates based on APIs as well,  like UPS, USPS, Fedex, Canada Post, Australia Post etc…). The 1st step is to create 2 shipping classes, in Products > Shipping Classes:

Create at least two shipping classes

You need to create a “Free” shipping class. You can create as many other shipping classes as ou want.

The next step is to assign classes to each product:

1st Product Settings
2nd Product settings

Now that you assigned classes to products, you need to define flat rates per classes in WooCommerce > Settings > Shipping > Flat Rate:

Shipping classes flat rates

Make sure that you setup a cost equal to zero for the free shipping class.

Finally you need to filter the shipping package using custom code and separate products from one package to two packages having each its own shipping method. Add the following snippet in the file called functions.php in your theme folder:

Please note that you need to use the free shipping method slug at line 14. And the final result in the cart is the following:

Shipping packages filtered in cart

That’s it! I hope that will save you some headaches! If you enjoyed this post, make sure you share it on Twitter!

Similar posts by awesome folks:

The author

About the author Remi: Hey! My name is Rémi Corson, i'm a WordPress Expert Developer, i create high level themes and plugins, and i provide free stuff every week on this website!


  1. sharon

    Hi, after created my shipping classes, I went to the shipping setting ‘flat rate’ and add cost but there is no dropdown. May I know what might be possible wrong? I’m using APG shipping.

  2. mgason

    I have free shipping setup in woocommerce as available for orders over $100. I setup 2 shipping classes “allow free” and “paid shipping” I assigned them to the relevant products.
    Products are separated into 2 packages.
    package 1 paid
    package 2 allow free
    Right now if package 1 is $55, and package 2 is $50 the customer gets the free option for package 2 because the order total is over $100. I want the over $100 free shipping rule to apply to the package total not the order total. The customer should not see free shipping as an option until the value of items in package 2 with assigned “allow free” class exceeds $100
    is that possible?

    1. Remi Post author

      Your snippet is absolutely fine, but I wanted to highlight in this post is that you can easily separate packages on a per product basis. I used free shipping, but it could be any other shipping method.

  3. Jaydeep

    Hello Remi,

    Hope you are doing well.

    I have a query regarding adding forcefully shipping method product base. So below is my scenario.

    For Example:

    I have 3 Products.

    Product Name: Test1
    Product Price: 5
    Shipping method set = Free shipping.

    Product Name: Test2

    Product Price: 10
    Shipping method set = ‘Flat rate’ cost = 15

    Product Name: Test3
    Product Price: 15
    Shipping method set = International Flat Rate Cost = 10

    So now If I have all above product in my cart than I need below functionality:
    1. Free shipping should be disable if the product of other shipping method in cart.
    2. I need to apply both rest of the shipping method to cart.
    => Flat rate for product Test1.
    => International Flat Rate for Test2

    So my cart should look like below:

    SUBTOTAL : 30
    Flat rate shipping for Test2: 15
    International Flat Rate Cost: 10
    Total: 55

    So How can I achieve this using WooCommerce Hooks and filters. because currently all shipping method available in cart page so user can select any of the method.

    Please help me for the same.


  4. Marcello

    Thx for this code, but i have a question about so
    Can u edit code for Multivendors ?
    I have try to use this code in multivendors site, work enough good, calculate more shipping method.
    But do not report to me which shipping has used the seller, just include in all cost

Leave a reply