Split cart items based on shipping class(Allow multiple shipping packages for one order based on shipping class)

The below code snippet will help you tor –> functions.php file.

In the above snippet, we can see there are three groups made.
– Group 1 has shipping class “class-a”.
– Group 2 has shipping class “class-b”.

So, if there are products of shipping class “class-a” and “class-b” in the cart, then the cart will split into two package components.

Package 1 will have product of shipping class “class-a”.
Package 2 will have product of shipping “class-b”.

This can be seen from the screenshot below :
Before snippet :

Cart before Spliting

Cart before Splitting

After Snippet:

Cart after splitting

Cart after splitting

In this case, there were 3 groups initially, hence showing 3 carts.

Note : Allowing multiple shipping the package for one order was introduced by WooCommerce version 2.1. So this snippet will be applicable for versions higher than 2.1.

Comments (5)

  • lrvanjani

    hello it does split cart items but does not display shipping cost associated class .it only displays flat rates but cost is not calculated.

    March 7, 2018 at 11:23 pm
    • Anindo

      Hi Irvanjani,

      Split cart will work only when the products in the cart are assigned with separate shipping classes.
      Can you kindly confirm whether your products have separate shipping classes assigned?

      Let us know if you have any query.

      March 8, 2018 at 1:21 pm
  • andrew

    doesn’t work for 3.x. Can we get updated code?

    July 4, 2017 at 10:38 pm
    • Veeresh

      Hello Andrew,

      Thank you for reaching us. The above snippet works for 3 groups of classes (Class IDs) as you can see the outcome is shown in the screen shot. Please raise a request on https://support.xadapter.com/hc/en-us with your complete query. We will definitely help you in fixing it.

      Thanks and regards,
      Team XA

      July 5, 2017 at 1:23 pm
  • anas.akhtar01

    after adding this code to the themes function.php file right below it still stays the same can you guide me on where i am going wrong.

    January 23, 2017 at 3:14 pm

Comments are closed.