Using Calculations with Flat Rate Shipping in WooCommerce

Recently I had a user that needed to charge a flat rate for shipping the first item and then a smaller amount for each additional item. It’s possible to set up this with Table Rate Shipping, but did you know you can also do some basic math with WooCommerce’s built-in Flat Rate Shipping? Let’s take a look at a quick example.

This user wanted to charge $29.90 for the first item in the order. Then for each additional item they wanted to charge and additional $9.90. How can we approach this?

First, we enter the $29.90 to cover the first item. To add to it, we use + operator. Here’s where the math comes in. We need to group the next calculations together so we’ll wrap them in parentheses. Here’s what we have now.

29.90 + ( )

To cover each additional item we can add this 9.90 * [qty] which will add an additional 9.90 for each item in the cart. The [qty] is a variable that represents the number of items in the cart. That gives us a basic equation like this:

29.90 + (9.90 * [qty])

There’s one significant issue with this. The first item will end up with a shipping charge of 39.80 instead of 29.90! Not good. We need a way to not charge the item cost on the first item.

To do that we need one more set of parentheses to modify the quantity. We can use the quantity variable and just subtract 1 from it since the first item is covered by the initial 29.90 amount. That gives us a final equation like this:

29.90 + ( 9.90 * ([qty] -1) )

Now customers are charged $29.90 for the first item then an additional $9.90 for each item after that. With a little bit of practice you can use Flat Rate Shipping for some situations where you might think you need a full fledged Table Rate setup. If you have any creative uses for math with Flat Rate Shipping, share them with us in the comments.

Leave a Reply

%d bloggers like this: