Splitting Shipping Packages (1)

In WooCommerce version 2.1 a new feature was introduced that allowed one order to have multiple shipping packages. Having multiple shipping packages can come in handy in various situations. One that comes to mind at first is when you actually have multiple packages, for example when you can’t ship items together, or when someone has an order that should ship via two different vendors.
Or the other obvious scenario, having to ship one order to multiple different destinations.

Another very useful use-case that a other WooCommerce user pointed me too not long ago was the ability to allow free shipping on just a specific set of products. When using a shipping carrier plugin like UPS it can be hard to set this up, but when splitting your order into multiple packages, and then setup free shipping (with WooCommerce Advanced Free Shipping for example) you can target only the package with the free shipping items, while the UPS plugin still gets the shipping cost for the other products.

Splitting Shipping Package

Just to give a clear example of what ‘splitting a shipping package’ means, this is how it would look like for the user when shipping multiple packages;

woocommerce-split-shipping-packages-example

Before actually splitting a order in multiple packages, you should first understand what a shipping package is exactly. Obviously a shipping package contains a part of the products to ship, but besides that, it also contains information like the cost, applied coupons and the destination address. A shipping package looks a bit like the following:

  • Contents
    • {{ All package contents }}
  • Contents cost
  • Applied Coupons
    • 10_OFF
  • User
    • User ID
  • Destination
    • Country
    • State
    • Postcode
    • City
    • Address
    • Address_2
Update I’ve build a plugin that allows you to split the cart into multiple packages. If you’re not comfortable with the code snippets below you may want to checkout the WooCommerce Advanced Shipping Packages plugin.

Splitting Shipping Package on Shipping Class

The follow code snippet will split the shipping package based on the shipping class. Each product that has a shipping class A will be split into a separate package from the other products.

Splitting Shipping Package on Product ID

If you want to split the shipping package based on product IDs you can replace the top part of the code with the following (partial code);

This will setup a separte shipping package for the products with the ID 188, 189 and 190.

Splitting Shipping Package on Category

The following code is similar to the (partial) code above. Use it by copying into the full code as seen as the first code snippet in this post.

Changing the shipping package name

When you’ve implemented the code above, the shippng should look something like this;

woocommerce-split-shipping-packages-example

 

As you can see, there are two shipping packages, each where the user can select a shipping method. One thing that you will see is that the shipping packages are called Shipping #x. If you want to change this, you’re in bad luck, currently it is not possible to change that package name.

I made a Pul Request to WooCommerce in order to allow the re-naming of the shipping package name, so you can call it what you want from within the shipping package array (as you saw in the first code snippet). When this Pull Request is accepted and it is in WooCommerce Core, I will update this post to include the new feature.

Setting Up Shipping Based on Shipping Package

Not all shipping plugins support shipping packages, so make sure you test everything extensively so your customers will pay the right amount on shipping cost.

My own WooCommerce Advanced Shipping plugin supports shipping packages.

  • Jeroen Sormani

    I'm a professional WordPress plugin developer on a mission to create the best plugins for my clients. I'm specialised in developing general WordPress, WooCommerce and Easy Digital Downloads plugins.

    Interested in talking about a WordPress project? Get in touch!

    Follow me on Twitter
  • 23 thoughts on “Splitting Shipping Packages in WooCommerce

    Matteo Raggi March 27, 2016 at 10:10 am

    Nice! And what about a sampel code about the vendors? For example I would like to see a sampel code for the WC MARKETPLACE multivendors plugin: https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor

    jeroen March 27, 2016 at 6:38 pm

    HI Matteo,

    Unfortunately I don’t have a code snippet available for that..

    If you end up creating one, feel free to include it here 🙂

    Jeroen

    A Hayes March 31, 2016 at 2:34 pm

    Where should this code be inserted? Does it go in the woocommerce-advanced-shipping/woocommerce-advanced-shipping.php? And if so, where should it be added?

    jeroen April 3, 2016 at 12:35 am

    Hi Angela,

    I wrote this blog post about code snippets that I can recommend 😉
    https://shopplugins.com/how-to-add-a-code-snippet-to-your-site/

    Cheers,
    Jeroen

    Megan Duckett April 2, 2016 at 12:14 am

    My site developer has been working with Jeroen to improve the shipping scenarios on our modestly sized apparel sales site. The challenges we had related to splitting shipping classes and assigning different rates and rules to products that are drop shipping internationally versus locally “all within a single order”. Jeroen has been so incredibly responsive and helpful! Already we have implemented the site improvements and could not be more pleased. Both my programmer and I highly recommend Jeroen and want to share our positive experience with him. Thank You. Megan Duckett. Rock’n Roll Outfitters.

    Fanie July 27, 2016 at 3:53 am

    Very cool! Thank you so much for your advice! I am now going to subscribe 🙂

    James September 2, 2016 at 7:05 am

    Hi Jeroen,

    This is awesome and I’ve used it to save money we were losing on shipping so thank you. However, there’s something I’m trying to debug. When AJAX is enabled on the checkout page. This function stalls the AJAX loading and it never completes. Any idea why that is? It seems that the data isn’t being passed over from cart to checkout. This has proven nearly impossible to debug. Please help! Thanks!

    Jeroen September 2, 2016 at 9:26 am

    Hi James,

    Just tested the code for splitting on shipping class, and everything seems to work for me. It could be you have a plugin running that causes an error behind the scenes, preventing from data being send back and the loading to be stopped / table to be refreshed.

    Should be able to find a error in the error log in such case.

    Cheers,
    Jeroen

    ms September 25, 2016 at 1:51 pm

    Hi,

    Do you have news from woocommerce regarding to your pul request for shipping package name?

    Is there a way to follow your request? link?

    Thanks!

    Jeroen September 25, 2016 at 9:24 pm

    Hi Marius,

    I don’t have a direct link right now, but you can search by author on GitHub.
    The package name can be filtered right now.

    Cheers,
    Jeroen

    Tom October 19, 2016 at 8:51 am

    Hi,

    I used the shipping on class for my online shop and it works awesome. The shipping costs of all products which belong to this one class are seperated from the rest of the order. 🙂

    Now I need the shop to deal with another class the same way. The shipping costs of those class shouldn´t be added to the costs of the first class I already splitted. So, there has to be a third field of splitted shipping costs.
    I tried a few things but the shop always adds the shipping costs to the costs of the first class.
    Is there a way to realise this additonal seperation somehow?

    Jeroen October 19, 2016 at 2:37 pm

    Hi Tom,

    You can copy a part of the code and create a third shipping package.

    If you’re not that familiar with code, a new extension has actually been released yesterday that would also be able to help you with that 😉 https://woocommerce.com/products/woocommerce-advanced-shipping-packages/

    Feel free to reach out through the contact form if you need some further advise.

    Cheers,
    Jeroen

    shawn November 28, 2016 at 10:53 pm

    Hi,
    This is exactly what I’m looking for I believe. Does your advanced plugin do the same without code? Does it support the woocommerce ups and usps shipping cost plugin? Thank you for your time.

    Jeroen November 28, 2016 at 11:02 pm

    Hi Shawn,

    Yes the Advanced Shipping Packages plugin does the same without code.
    I haven’t tested it with any shipping carrier plugin, but I do think it should work out of the box.

    Cheers,
    Jeroen

    shawn November 29, 2016 at 6:39 pm

    Can I display certain shipping options based on class. example, I only want to show flat rate shipping options for certain classes and and then for other classes i want to be able to show ups and usps. also what if i run a free shipping promotion? can i have a coupon apply to certain or all classes.

    I’m currently using the packages grouping plugin and It is exactly what I need except the shipping isn’t transfering correctly to paypal so I hope I can do the same with your plugin.

    Thank you for actually responding to support request. I think your the only one out there.

    Jeroen November 29, 2016 at 7:21 pm

    Hi Shawn,

    Yes you can setup the shipping packages / options based on the shipping class.
    A free shipping coupon should also be possible, though I also haven’t tested that scenario.

    I’m not familiar with the packages grouping plugin, but WooCommerce sends over the data to PP so that is not interfered by the plugin itself.

    PS. note that I’m not responsible for the support of the Advanced Shipping Packages plugin, this is done by WooCommerce.com, so if you want to be sure / guarantees about this you’d need to contact them as I can’t speak on their behalf 😉

    Cheers,
    Jeroen

    shawn November 29, 2016 at 7:34 pm

    Thank you,
    Do you have a development company that offers custom work incase I need anything in the future?

    shawn November 29, 2016 at 9:10 pm

    How does this integrate with shipping zones? Do you still use zones or does this override all that? Thank you, I just want to make sure this does what I hope.

    Jeroen November 30, 2016 at 8:57 am

    Yes, you can contact me here: http://jeroensormani.com/hire-me

    The plugin doesn’t create any shipping rates so it is not related to shipping zones in any way like that. Please contact me through the contact form if you have any further questions.

    Cheers,
    Jeroen

    Jared Wilcox December 17, 2016 at 12:25 am

    Jeroen,

    I am trying to use your code to apply free shipping to a product with a specific shipping class. The only problem is that it is adding the free shipping method to all packages in the cart. Even the package that does not have the free shipping class.

    The goal is to have one package with free shipping available, and the other package with only the paid options available and no free shipping option.

    Is this possible?

    Thank you,
    Jared

    Jeroen December 17, 2016 at 10:09 pm

    Hi Jared,

    It might be that the free shipping option you’re using isn’t compatible with shipping packages.
    My Advanced Shipping plugin definitely is compatible with shipping packages and would allow you to set that up.

    Cheers,
    Jeroen

    Angelo December 23, 2016 at 6:45 am

    Hi Jeroen,
    it is incredible how you can manage WP problemas and help people to clean up their problems with it! Thank you!

    I have a question about a problem that, even looking for a lot of time in google i cannot find a valid solution:

    i have a woocommerce shop where i have products with shipping cost included for national shipping (A) and products where the product weight adds to calculate the total shipping weight (B).

    Problems comes when, in the same order, i have both type of products….. i dont want woocommerce to calculate the shipping including the A product weight…

    You would say: so put the A product weigth to 0… The answer would be: I cannot, because, for international shipping i need to know the product weight…

    So, which solution you would take? I thought to find a way to exclude product A weight from the shipping calculation for national shipping and leave as it is in the others shipping… but i don’t know how!

    Well, i hope i describe in a comprehensive way the problem…thank you very much!

    Jeroen December 23, 2016 at 9:45 am

    Hi Angelo,

    One (important) Q came from your message: how do you want to calculate the cost?

    If you want to use a shipping carrier / live quotes it is a different story then when using your own shipping rates.

    If you setup your own rates, you can use my Advanced Shipping plugin to setup cost based on the weight of a product or shipping class (or category). http://codecanyon.net/item/woocommerce-advanced-shipping/8634573

    In case its live quotes, what you could try is setting up two packages as per this post, and using my Advanced Shipping plugin again to setup a free shipping rate (and hide others) for the A package.

    Hope that helps 😉

    Cheers,
    Jeroen

    Leave a Reply