Skip to main content

Cart & Pricing Strategies

These examples show how to calculate shipping based on cart totals, weight thresholds, and quantity-based adjustments. Copy any template below and adapt it to your needs.

Default Rate Lab function

{% liquid
assign service_name = "Rate Lab Test"
assign kayak_lines = shopify_rate_check.line_items | select: "sku", "abkayak" | size
assign kayak_surcharge = kayak_lines | times: 5000
assign total_weight = shopify_rate_check.line_items | sum: "grams"
assign weight_price = total_weight | divided_by: 1.5 | round
%}
{
  "rates": [{
    "service_name": {{ service_name | json }},
    "service_code": "RL",
    "currency":     "USD",
    "total_price":  {{ total_weight | plus: kayak_surcharge }}
  }]
}
  • Calculates a base price from cart weight.
  • Adds a surcharge for “abkayak” SKUs to cover oversize handling.

Percentage of cart subtotal

{% liquid
  assign cart_subtotal = 0
  for item in shopify_rate_check.items
    assign line_total = item.price | times: item.quantity
    assign cart_subtotal = cart_subtotal | plus: line_total
  endfor

  assign shipping_price = cart_subtotal | times: 12 | divided_by: 100
  assign shipping_price = shipping_price | at_least: 500 | at_most: 2500
%}
{
  "rates": [
    {
      "service_name": {{ "12% Cart Shipping" | json }},
      "service_code": "PERCENT",
      "currency": {{ shopify_rate_check.currency | json }},
      "total_price": {{ shipping_price }},
      "description": {{ "12% of cart subtotal, between $5 and $25" | json }}
    }
  ]
}
  • Charges 12% of the cart subtotal.
  • Uses guardrails to enforce a minimum and maximum shipping charge.

Weight and spend combined

{% liquid
  assign cart_subtotal = 0
  assign total_weight = 0

  for item in shopify_rate_check.items
    assign line_total = item.price | times: item.quantity
    assign cart_subtotal = cart_subtotal | plus: line_total

    assign line_weight = item.grams | times: item.quantity
    assign total_weight = total_weight | plus: line_weight
  endfor

  assign shipping_price = 900
  if total_weight > 10000
    assign shipping_price = 1400
  endif

  if cart_subtotal >= 20000 and shopify_rate_check.destination.country == "US"
    assign shipping_price = 0
  endif
%}
{
  "rates": [
    {
      "service_name": {{ "Weight & Spend Logic" | json }},
      "service_code": "WEIGHT_PRICE",
      "currency": {{ shopify_rate_check.currency | json }},
      "total_price": {{ shipping_price }},
      "description": {{ "Base $9, heavier than 10kg is $14, free over $200 spend in the US" | json }}
    }
  ]
}
  • Starts with a flat fee, increases for heavier orders, and offers free shipping for high-value US orders.

First item plus incremental extras

{% liquid
  assign shippable_qty = 0
  for item in shopify_rate_check.items
    if item.requires_shipping
      assign shippable_qty = shippable_qty | plus: item.quantity
    endif
  endfor

  assign additional_units = shippable_qty | minus: 1 | at_least: 0
  assign incremental = additional_units | times: 250
  assign shipping_price = 850 | plus: incremental
%}
{
  "rates": [
    {
      "service_name": {{ "First Item + Extras" | json }},
      "service_code": "PER_ITEM",
      "currency": {{ shopify_rate_check.currency | json }},
      "total_price": {{ shipping_price }},
      "description": {{ "First shippable item is $8.50, each additional adds $2.50" | json }}
    }
  ]
}
  • Counts only shippable items.
  • Adds $2.50 for every additional unit beyond the first.
Looking for more specialized rules? Continue to Vendor-Based Logic.