How to Calculate WooCommerce Shipping Cost Based on Cart Line Items
By default, shipping rules based on quantity count the total number of product quantities in the cart. However, there are situations where you may want to calculate shipping based on the number of different products (cart line items) instead.
The Flat Rate Shipping Plugin for WooCommerce includes an advanced rule that allows you to calculate shipping costs based on cart line items, giving you greater flexibility when creating shipping rules.
In The Article
What are cart line items?
A cart line item represents a unique product in the shopping cart, regardless of its quantity.
For example:
| Product | Quantity | Cart Line Item Count |
|---|---|---|
| Product X | 2 | 1 |
| Product Y | 2 | 1 |
| Product Z | 2 | 1 |
Although the total quantity is 6, the cart contains only 3 line items because there are three unique products.
This differs from quantity-based rules, which would count all six items.
Configuration steps
- Install and activate the Dotstore Flat Rate Shipping Plugin.
- Go to Dashboard → Dotstore → Flat Rate Shipping.
- Create or edit a shipping method.
- Navigate to Advanced Settings and Add a new Advanced Rule.
- Select Cart Line Item as the rule type.

- Save the shipping method.
- Test the rule at checkout.
Real Examples
Example 1: Shipping cost for up to three cart line items
Rule
Apply a shipping cost of $10 when the cart contains 1–3 cart line items.
Customer cart
| Product | Quantity |
|---|---|
| Product X | 2 |
| Product Y | 2 |
| Product Z | 2 |
Result
- Total Quantity: 6
- Cart Line Items: 3
- Shipping Cost: $10
Although there are six products in total, the shipping rule is applied because the cart contains only three unique products.
Expected Outcome
Once configured, the shipping rule evaluates the number of unique products (cart line items) instead of the total product quantity. This gives you greater control over shipping costs for carts containing multiple product types.