@hyperse-hub/hps-plugin-shipping-tiered-pricing
Tiered shipping pricing for Vendure.
This plugin adds:
- A Shipping Calculator:
tiered-pricing-shipping-calculator
- A Shipping Eligibility Checker:
tiered-pricing-shipping-eligibility-checker
It is designed for cases where shipping cost grows with the total quantity in the order, with optional “free shipping” conditions.
Requirements
- Vendure
>= 3.0.0
- Node.js
>= 20
Install
yarn add @hyperse-hub/hps-plugin-shipping-tiered-pricing
Setup (Vendure config)
Add the plugin to your Vendure config:
Note: init() currently has no options, but is kept for the standard Vendure plugin initialization pattern.
How it works
1) Eligibility (where/when the shipping method is available)
The eligibility checker validates:
- Minimum order amount:
order.subTotalWithTax >= orderMinimum
- Shipping destination: the order shipping country must belong to at least one of the configured Zone names
The checker argument zones is a comma-separated list of Zone names (as created in Vendure Admin).
Example: Europe, Asia, United States
Implementation detail:
- The plugin reads
order.shippingAddress.countryCode
- It loads all zones from Vendure and matches them by
Zone.name
- It then checks whether the shipping country code is a member of any matched zone
2) Price calculation (tiered pricing)
The calculator price is computed as:
[
tierPrice = \max(0, totalQuantity - growthPriceTierThreshold) \times growthPriceRate
]
[
finalPrice = basePrice + tierPrice
]
Where:
totalQuantity is order.totalQuantity
growthPriceTierThreshold is the “free tiers” threshold before growth starts
growthPriceRate is how much to add per extra tier (after threshold)
basePrice is always included
Example
basePrice = 500 (e.g. $5.00 in minor units)
growthPriceTierThreshold = 2
growthPriceRate = 200
For an order with totalQuantity = 5:
tierPrice = (5 - 2) * 200 = 600
finalPrice = 500 + 600 = 1100
3) Free shipping logic (important)
Free shipping triggers only when all three constraints are enabled and satisfied:
freeMinAmount > 0 and order.subTotalWithTax >= freeMinAmount
freeMinQuantity > 0 and order.totalQuantity >= freeMinQuantity
freeMaxQuantity > 0 and order.totalQuantity <= freeMaxQuantity
If any of these three values is 0, then free shipping is effectively disabled (because the implementation requires all three constraints to be active).
When free shipping applies, the calculator returns:
price = 0
priceIncludesTax = true
taxRate = 0
metadata.isFree = true
metadata.shouldPay = finalPrice (the shipping fee that would have been charged without free shipping, useful for UI display)
Example result (free shipping):
Example result (not free shipping):
Configuration reference
You configure this plugin by creating/editing a Shipping Method in Vendure Admin and selecting:
- Eligibility checker:
tiered-pricing-shipping-eligibility-checker
- Calculator:
tiered-pricing-shipping-calculator
Eligibility checker arguments
- orderMinimum (
int, default 0): Minimum subTotalWithTax required for eligibility.
- zones (
string, default "United States"): Comma-separated Zone names.
Calculator arguments
- basePrice (
int, default 0): Base shipping price in minor units.
- growthPriceRate (
int, default 0): Price added per tier after threshold.
- growthPriceTierThreshold (
int, default 2): Quantity threshold before tier growth starts.
- freeMinQuantity (
int, default 0): Enable + minimum quantity for free shipping.
- freeMaxQuantity (
int, default 0): Enable + maximum quantity for free shipping.
- freeMinAmount (
int, default 0): Enable + minimum subTotalWithTax for free shipping.
Recommended setup steps (Admin UI)
- Create/verify Zones in Settings → Zones (make sure the zone names match what you will input).
- Create a new Shipping Method.
- Add the eligibility checker
tiered-pricing-shipping-eligibility-checker.
- Set
orderMinimum and zones.
- Add the calculator
tiered-pricing-shipping-calculator.
- Set
basePrice, growthPriceTierThreshold, growthPriceRate.
- (Optional) Configure free shipping by setting all of:
freeMinAmount, freeMinQuantity, freeMaxQuantity.
Development
From this package folder:
yarn install
yarn build
yarn lint
yarn typecheck
yarn test
E2E / local dev server
FAQ
Why is my shipping method not available at checkout?
- Ensure
order.subTotalWithTax meets orderMinimum.
- Ensure the shipping address has a
countryCode.
- Ensure the
zones string contains Zone names that exist in Vendure, and that those zones include the shipping country.
I set freeMinAmount, but free shipping never triggers
Free shipping requires all of freeMinAmount, freeMinQuantity, and freeMaxQuantity to be > 0, and all conditions must match.
License
MIT