I’ve seen some variation of this question multiple times from both new and experienced WooCommerce shop owners: Can I charge shipping based on the number of items in the cart instead of just a flat fee?
Definitely doable. ? The best part? You don’t even need any plugins or code snippets to do it — you can do quantity-based shipping within WooCommerce itself.
Many shop owners use the built-in WooCommerce shipping zones and rates to create their shipping fee structures. You can find these under WooCommerce > Settings > Shipping.
Notice that many of my shipping methods are flat rate methods, such as those named “Ground” or “Expedited”. By default, these charge a set rate for that zone, such as $5 per order.
However, you can do a lot more with flat rates than simple costs! This is where I encourage you to read the tooltips in WooCommerce core more frequently. ?
You can add advanced costs such as quantity-based costs or additional fees, to your flat rate shipping. You can use this to include the item quantity in your shipping cost formula with the
Now, instead of charging $3 per order, I can charge $3 per item in the cart, which means that my shipping rate can adjust based on the number of items being ordered.
This lets you create WooCommerce shipping per item rather than per order with the built-in shipping tools.
Since shipping tends to bring up all sorts of questions, let’s look at a more complex example I saw in the WooCommerce community Slack recently: I need to charge shipping in multiples of two as you can get two items per container. How would I go about doing that?
This question is interesting because it sets up a tiered shipping system rather than strictly pricing per item — this needs to change shipping for every two items, not for every item.
While more complex shipping like this can’t be done with the core tools, you could create tiered shipping with the Table Rate Shipping extension for WooCommerce. This plugin lets you create rates per item count, so you could do a table of rates like this:
|Item count||Shipping cost|
|1 to 2||$3|
|3 to 4||$6|
|5 to 6||$9|
|7 to 8||$12|
|…and so on|
The benefit here is that, based on the description in my question above, I think this is supposed to be per line item quantity (given it packs similar items in a box), which Table Rate Shipping can account for with “calculated rates per line item” as the calculation type.
This will then change the rate using your tiers for each line item’s quantity, providing the summed total as the shipping cost to the customer:
Table Rate Shipping can give you advanced WooCommerce tiered shipping based on item count, and other properties such as weight or price.
For developers, you can create even more complex shipping schemes or tiered pricing using the
woocommerce_shipping_rate_cost filter (requires WooCommerce 3.2+). This lets you adjust the cost of any shipping method programmatically.
You should be comfortable with PHP code and WordPress hooks to use the examples in this section.
Let’s take the above example for tiered pricing, but do it based on the entire cart item quantity, not per line, using this filter.
First, I’ll set up the base rates for my shipping methods. I’m going to use $3 as my per box price, and then I’ll programmatically change the box count in a code snippet.
Now, I’ll filter the method cost, multiplying this base cost by my box count. I’ll get the box count by rounding the cart item quantity divided by 2 (which should give me whole numbers always for my box count). Note that you could also use a modulus operator here to check for instances where you have no remainder for cart item qty ÷ by 2.
Notice that I’m using the instance IDs for the rates I want to use this tiered pricing for. You can get this by hovering over the link to each shipping rate and you’ll see
&instance_id=number in the URL (or you can inspect the HMTL for the rate to get this).
Now I’ve created a system in which I’ll get the total box count for all cart items, assuming any of my products fit 2 per box, and multiply that to the per box cost. If I have 2 items, this charges for one box:
While having 5 cart items charges for 3 boxes:
That’s it! There are many ways to create WooCommerce shipping per item, including using the item quantity directly, or by creating more advanced tiered rates via plugins and customization.