Skip to main content

Variable Hierarchy & Usage

Written by Haris Spahovic

When you see a variable listed under a "Parent," it means it lives inside that object. In your templates, you will typically access these using a "for loop" to list every item in that group.


1. Customer & Store Credit

Manage customer loyalty and multiple currency balances.

  • customer.total_ordersInteger. Total number of orders placed by the customer.

    • {{ customer.total_orders }}

  • customer.total_spent - Integer (cents). Total money spent by the customer

    • {{ customer.total_spent | money }}

  • customer.store_creditInteger (cents). Total credit balance across all accounts.

    • {{ customer.store_credit | money }}

  • customer.store_credit_currencyString. The currency code for the total balance (e.g., "USD").

    • {{ customer.store_credit_currency }}

  • customer.store_credit_accountsArray. All individual store credit accounts.

    • ...amountInteger (cents). The credit amount in a specific account.

    • ...currencyString. The currency code for that specific account (e.g., "EUR").

  • Code snippet

{% for account in customer.store_credit_accounts %}

{{ account.amount | money }} {{ account.currency }}

{% endfor %}


2. Shopify Bundles (Line Items)

Identify bundles and break them down into their individual components.

  • line_item.is_bundleBoolean. true if the item is a Shopify bundle.

    • {% if line_item.is_bundle %}Bundle{% endif %}

  • line_item.componentsArray. Items inside the bundle (empty array [] when not a bundle).

    • ...titleString. Name of the component.

    • ...variant_titleString. The specific variant (e.g., "Blue / Large").

    • ...skuString. The SKU of the component.

    • ...quantityInteger. Number of units included in the bundle.

    • ...priceInteger (cents). Individual price of the component.

    • ...line_priceInteger (cents). Total price for this component (price × quantity).

    • ...variant_idInteger. Unique ID for the variant.

    • ...requires_shippingBoolean. Whether this specific part requires shipping.

      Code snippet

{% if line_item.is_bundle %}

{% for component in line_item.components %}

{{ component.title }}{% if component.variant_title != blank %} - {{ component.variant_title }}{% endif %}

SKU: {{ component.sku }}

Qty: {{ component.quantity }} × {{ component.price | money }} = {{ component.line_price | money }}

{% endfor %}

{% endif %}


3. Shipping, Customs & Taxes

Access specific data for international compliance and order tracking.

  • order.po_numberString. The Purchase Order number for the order.

    • {% if order.po_number != blank %}PO {{ order.po_number }}{% endif %}

  • line_item.has_tax_linesBoolean. true if taxes are applied to the line item.

    • {% if line_item.has_tax_lines %}(Tax applied){% endif %}

  • line_item.province_of_originString. The state/province code of origin (e.g., "CA").

    • {{ line_item.province_of_origin }}

  • line_item.country_hs_codesArray. Per-country harmonized system codes.

    • ...country_codeString. The destination country code (e.g., "DE").

    • ...harmonized_system_codeString. The HS tariff code for that country (e.g., "6203.42").

  • Code snippet

{% for hs in line_item.country_hs_codes %}

{{ hs.country_code }}: {{ hs.harmonized_system_code }}

{% endfor %}


Important Implementation Notes

  • Currency Formatting: Store credit amounts and component prices are provided in cents. Always use the | money filter for correct display.

  • Multi-Currency Handling: customer.store_credit_currency reflects the first account's currency. For merchants with multi-currency accounts, use the currency field inside the store_credit_accounts loop.

  • Bundle Logic: is_bundle defaults to false (not nil), making it safe for boolean checks. While components returns an empty array for non-bundles, using the is_bundle guard is recommended for cleaner template logic.

Did this answer your question?