Skip to main content

Destination Controls

Adjust shipping based on where the order is going - country, region, postal code, or address type.

Postal code tiering

{% liquid
  assign postal_code = shopify_rate_check.destination.postal_code | upcase
  assign prefix = postal_code | slice: 0, 3

  if prefix == "941"
    assign shipping_price = 0
    assign description = "Free local delivery for San Francisco 941xx"
    assign service_name = "Local Delivery"
    assign service_code = "LOCAL_FREE"
  elsif prefix == "997" or prefix == "999"
    assign shipping_price = 2800
    assign description = "Remote area surcharge applies"
    assign service_name = "Remote Area Shipping"
    assign service_code = "REMOTE_SURCHARGE"
  else
    assign shipping_price = 1200
    assign description = "Standard continental US shipping"
    assign service_name = "Standard Shipping"
    assign service_code = "STANDARD"
  endif
%}
{
  "rates": [
    {
      "service_name": {{ service_name | json }},
      "service_code": {{ service_code | json }},
      "currency": {{ shopify_rate_check.currency | json }},
      "total_price": {{ shipping_price }},
      "description": {{ description | json }}
    }
  ]
}
  • Branches on the postal code prefix to serve local delivery, remote surcharges, or standard shipping.

State-based restrictions

{% liquid
  assign region = shopify_rate_check.destination.province | upcase
  assign restricted_state_list = "AK,HI,PR" | split: ","
  assign restricted_skus = "BATTERY-001|BATTERY-010"

  assign is_restricted_region = false
  for state in restricted_state_list
    if state == region
      assign is_restricted_region = true
    endif
  endfor

  assign has_restricted_sku = false
  for item in shopify_rate_check.items
    if restricted_skus contains item.sku
      assign has_restricted_sku = true
    endif
  endfor

  assign allow_rates = true
  if is_restricted_region and has_restricted_sku
    assign allow_rates = false
  endif
%}
{
  "rates": {% if allow_rates %}
    [
      {
        "service_name": {{ "Standard Shipping" | json }},
        "service_code": "STANDARD",
        "currency": {{ shopify_rate_check.currency | json }},
        "total_price": 1800,
        "description": {{ "Allowed because restricted SKUs are not headed to blocked states" | json }}
      }
    ]
  {% else %}
    []
  {% endif %}
}
  • Blocks rates entirely when restricted SKUs ship to prohibited states.
  • Demonstrates how to return an empty array to stop Shopify from showing the rate.

Offshore surcharge

{% liquid
  assign offshore_regions = "AK,HI,PR" | split: ","
  assign region = shopify_rate_check.destination.province | upcase
  assign is_offshore = false

  for code in offshore_regions
    if code == region
      assign is_offshore = true
    endif
  endfor

  assign base_price = 1000
  assign surcharge = 0
  if is_offshore
    assign surcharge = 1500
  endif
  assign total_price = base_price | plus: surcharge
%}
{
  "rates": [
    {
      "service_name": {{ "Standard Shipping" | json }},
      "service_code": "STANDARD",
      "currency": {{ shopify_rate_check.currency | json }},
      "total_price": {{ total_price }},
      "description": {{ "Adds $15.00 for AK/HI/PR destinations" | json }}
    }
  ]
}
  • Adds a surcharge when shipping to non-continental regions.
  • Keeps the same base service for all other destinations.

PO box filtering

{% liquid
  assign address = shopify_rate_check.destination.address1 | downcase | replace: ".", ""
  assign is_po_box = address contains "po box"

  assign ground_price = 1200
  assign expedited_price = 2200
%}
{
  "rates": [
    {
      "service_name": {{ "Postal Ground" | json }},
      "service_code": "GROUND_PO",
      "currency": {{ shopify_rate_check.currency | json }},
      "total_price": {{ ground_price }},
      "description": {{ "Safe delivery for PO boxes" | json }}
    }
    {% unless is_po_box %}
    ,
    {
      "service_name": {{ "Courier Express" | json }},
      "service_code": "EXPRESS",
      "currency": {{ shopify_rate_check.currency | json }},
      "total_price": {{ expedited_price }},
      "description": {{ "Hand-delivered express service" | json }}
    }
    {% endunless %}
  ]
}
  • Always offers a PO-box-safe method.
  • Hides the express option when the destination is a PO box.
Next, see how product attributes can influence shipping in Product-Level Qualifiers.