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

[vc_cta h2=”The Below Code Works for the Following Plugins:”]

[/vc_cta]

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.

5 thoughts on “Split cart items based on shipping class(Allow multiple shipping packages for one order based on shipping class)”

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

    1. 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.
      Regards,

    1. 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,
      Veeresh.
      Team XA

  2. 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.

Comments are closed.

Scroll to Top