Skip to main content

Understanding Your Order Data

When calculating shipping rates, your Liquid template has access to detailed information about the order through the shopify_rate_check object. This page explains what data is available and how to use it.

The rate check object

In the top right panel of Rate Lab, you’ll see a JSON object containing all the order information Shopify provides. Your Liquid template accesses this data to make shipping decisions.

Basic structure

shopify_rate_check
  ├── rate (origin information)
  ├── items (or line_items - the products being ordered)
  ├── destination (shipping address)
  ├── currency
  └── locale

Line items (products in cart)

Access products using shopify_rate_check.items or shopify_rate_check.line_items:
{% for item in shopify_rate_check.items %}
  {{ item.name }}         <!-- Product name -->
  {{ item.quantity }}     <!-- How many -->
  {{ item.grams }}        <!-- Weight per unit -->
  {{ item.price }}        <!-- Price per unit in cents -->
  {{ item.sku }}          <!-- Product SKU -->
  {{ item.vendor }}       <!-- Product vendor -->
  {{ item.requires_shipping }}  <!-- true/false -->
{% endfor %}

Common patterns with items

Calculate total weight:
{% assign total_weight = shopify_rate_check.items | sum: "grams" %}
Calculate cart subtotal:
{% assign subtotal = 0 %}
{% for item in shopify_rate_check.items %}
  {% assign line_total = item.price | times: item.quantity %}
  {% assign subtotal = subtotal | plus: line_total %}
{% endfor %}
Count items by SKU:
{% assign kayak_items = shopify_rate_check.items | where: "sku", "KAYAK-01" %}
{% assign kayak_count = kayak_items | size %}
Filter by vendor:
{% assign acme_items = shopify_rate_check.items | where: "vendor", "Acme Corp" %}
Check for specific products:
{% assign has_hazmat = false %}
{% for item in shopify_rate_check.items %}
  {% if item.properties contains "hazmat" %}
    {% assign has_hazmat = true %}
  {% endif %}
{% endfor %}

Destination (shipping address)

Access shipping address details:
{{ shopify_rate_check.destination.country_code }}  <!-- US, CA, GB, etc. -->
{{ shopify_rate_check.destination.province_code }}  <!-- State/province (NY, ON, etc.) -->
{{ shopify_rate_check.destination.city }}
{{ shopify_rate_check.destination.postal_code }}

Geographic logic examples

Charge more for Alaska/Hawaii:
{% assign base_price = 995 %}
{% if shopify_rate_check.destination.province_code == "AK" or shopify_rate_check.destination.province_code == "HI" %}
  {% assign base_price = 1995 %}
{% endif %}
Block PO boxes:
{% assign address = shopify_rate_check.destination.address1 | downcase %}
{% if address contains "po box" or address contains "p.o. box" %}
  <!-- Return no rates or a special handling rate -->
{% endif %}
International surcharge:
{% assign surcharge = 0 %}
{% if shopify_rate_check.destination.country_code != "US" %}
  {% assign surcharge = 1500 %}
{% endif %}

Currency

The order’s currency is available at:
{{ shopify_rate_check.currency }}  <!-- USD, CAD, EUR, etc. -->
Always return rates in the same currency:
{
  "rates": [{
    "service_name": "Standard Shipping",
    "service_code": "STANDARD",
    "currency": {{ shopify_rate_check.currency | json }},
    "total_price": 995
  }]
}

Product properties and metafields

Items can have custom properties and metafields that you can use in your logic:
{% for item in shopify_rate_check.items %}
  {% if item.properties.gift_wrap == "true" %}
    <!-- Add gift wrap fee -->
  {% endif %}
{% endfor %}

Advanced: Working with variants

Some rate checks include variant information:
{% for item in shopify_rate_check.items %}
  {{ item.variant_id }}
  {{ item.product_id }}
  {{ item.variant_title }}
{% endfor %}

Testing different scenarios

In Rate Lab’s top right panel, you can edit this data to test how your rates respond: Test heavier orders: Change "grams": 500 to "grams": 5000 on an item Test international shipping: Change "country_code": "US" to "country_code": "CA" Test high-value orders: Change item prices or quantities to create a large cart total Test specific products: Add or remove items, change SKUs, modify vendor names

Prices are always in cents

Remember: all price values in Rate Lab are in cents (or smallest currency unit):
  • "price": 1995 = $19.95
  • "price": 50 = $0.50
  • Your total_price should also be in cents

Next steps

Now that you understand what data is available, explore how to use it: