WooCommerce Flat Rate Shipping Formulas Explained
Use the three codes in the WooCommerce flat rate Cost box: qty for the number of items, cost for the price of the items, and fee for a percentage with a minimum and a maximum. Then combine them in one formula, test it at checkout and fix the common mistakes.
Watch the tutorial
This tutorial uses the three codes you can type in the WooCommerce flat rate Cost box, with only stock WooCommerce on a demo coffee shop: qty for the number of items, cost for the price of the items, and fee for a percentage with a minimum and a maximum. We combine them in one formula, use them in a shipping class cost, and test the result with real carts, at checkout and in a test order. Then we go through three common mistakes. No code needed.
Also on YouTube (opens in a new tab)
Read the transcript
Flat rate shipping is the simplest shipping method in WooCommerce, but its cost box can do much more than hold one number. In this tutorial, we'll use three codes in that box: quantity, cost, and fee. Then we'll combine them, add shipping classes, test at checkout, and fix the common mistakes. It's all stock WooCommerce, on our demo coffee shop, and we tested every formula in a real store.
Three codes go in the cost box, and each one sits in square brackets. [qty] is the number of items in the cart. [cost] is the total price of those items, before tax, and after any coupon. And fee works out a percentage, with an optional minimum and maximum.
Open WooCommerce, Settings, and Shipping. Then edit a shipping zone. Click Edit next to Flat rate. The Cost box is where formulas go. Hover over the question mark, and WooCommerce lists the codes for you. A plain number, like $6, charges the same on every order. That's the cart, with $6 shipping. Now let's make it smarter.
Start with [qty]. It counts items, not different products. To charge $2.50 for every item, type 2.50 * [qty]. Save, and look at the cart. Two bags of coffee, and one pack of filters, make three items. Shipping is $7.50. Add another pack of filters, and the fourth item makes it $10.
Next, [cost]. It's the total price of the items, before tax. For ten percent of the order, type [cost] * 0.10. The items add up to $42.50, so shipping is $4.25. It follows your discounts too. Apply a $10 coupon, and cost drops to $32.50, so shipping drops to $3.25.
The fee code does the same job, with a floor and a ceiling. Type fee in square brackets, with a percent, a minimum fee, and a maximum fee. Use straight quotes around each number. That's ten percent of the order, but never less than $5, and never more than $20. An $18 bag of coffee is only $1.80 at ten percent, so shipping rises to the $5 minimum. Three bags and a pack of filters come to $60.50, so shipping is $6.05. And the $289 home roaster would be $28.90, so shipping stops at the $20 maximum.
You can combine the codes in one formula, with plus, minus, times, divide, and round brackets. Say you want a $4 base fee, $1.50 for every item, and two percent of the order. Type 4.00, plus 1.50 times [qty], plus a fee with a percent of two. Our cart has three items worth $42.50. That's $4, plus $4.50 for the items, plus 85 cents for the percentage, so shipping is $9.35.
Shipping classes use the same codes. Every class cost box accepts a formula. Here, the Heavy items class costs $3 for each item in that class. Our cart has one bag of coffee, and two green coffee sacks. [qty] in the class box counts only the sacks, so it's two, not three. The flat rate is $5, and the sacks add $6, so shipping is $11. The Calculation type decides if classes add up, or only the most expensive one counts.
Now test it. A formula is only right when real carts agree with your math. Here's the cart with three items, and $9.35 shipping. Add one more pack of filters, and shipping goes up to $10.98. Then go through the checkout, because that's what your customers see. With an address in the zone, the flat rate shows its price. Place a test order, and open it. The shipping line matches, $10.98. Try a small cart, a big cart, and an address in each of your zones.
Mistake one. A formula WooCommerce can't read. Forget the square brackets, and type 2.50 * qty, then click Save. There's no error message. The box just closes. Open it again, and your old cost is still there. The cart still charges the old price. So use the exact codes, and a star for multiply, never the letter x.
Mistake two. Curly quotes. Copy a formula from a web page or a document, and the quote marks can turn curly. WooCommerce doesn't understand them. It saves without a warning, but the percent is ignored. This should be $5 plus ten percent, which is $6.80, and the cart says $5. Open the box again, and type the quotes by hand, straight ones. Save, and the cart says $6.80.
Mistake three. Tax on shipping. Your formula gives the price before tax. The Tax status setting decides if tax is added on top. In our demo store, the sales tax is eight percent. With Taxable, the $9.35 shipping is taxed too, and the tax is $4.15. Open the flat rate again, and set the Tax status to None. Now the tax drops to $3.40, the tax on the items alone. Whether shipping is taxed depends on where you sell, so check the rules for your area.
That's flat rate shipping formulas. [qty] counts items, cost is the order total, and fee takes a percentage with a minimum and a maximum. Combine them with plus and times, test with real carts, and watch your brackets, your quotes, and your tax setting. That's all for now. Come back to plugincity.net, for more WooCommerce tutorials.
What you will learn
- Where the flat rate Cost box is, and what the question mark tooltip lists
- Qty: the number of items in the cart, so a formula can charge per item
- Cost: the price of the items before tax and after coupons, so a formula can charge a share of the order
- Fee: a percentage with an optional minimum and maximum, and why its quotes must be straight
- How to combine a base fee, a price per item and a percentage in one formula
- That every shipping class cost box accepts the same codes, and counts only the items in that class
- How to test a formula with real carts, at checkout and in a test order
- Three common mistakes: a formula that cannot be read, curly quotes, and tax on shipping
Good to know
Everything shown is stock WooCommerce (version 11.2.2 in this video) with no extra plugins, and screens may look slightly different in other versions. The formulas are examples on a demo shop: your own prices, zones and tax rules will differ, so test every formula with real carts and a test order on your own store before it goes live. Filmed on a demo shop (Ridgeline Coffee Roasters) with sample products and prices in US dollars. The voice-over is a computer-generated voice.