Shopify Order Printer 的 Liquid 變數與篩選器參考資料

您可以使用 Liquid,透過 Shopify Order Printer app 建立自訂範本。使用 Liquid,您可以建立文字範本,並根據每筆訂單的獨特資料呈現內容。

本頁所列的 Liquid 參考資料是 the open-source version of Liquid 的擴充,供 Shopify Order Printer app 使用。若要依 order 和 shop 屬性渲染資訊,您可以使用本文提供的物件、標籤與篩選器清單來自訂您的範本。您也可以透過 Admin GraphQL API docs 了解物件欄位的詳細說明。

使用變數與屬性

在 Shopify Order Printer 範本中,核心資料物件為 order 和 shop。您可以使用 order.variable_name 來存取訂單屬性。

下列常用的訂單屬性可以在不加上 order. 前綴的情況下存取:

  • line_items
  • tax_lines
  • fulfillments
  • transactions
  • discounts
  • refunds
  • shipping_methods
  • customer

例如,若要存取商品項目變數,您可以使用 line_items 或 order.line_items。

Shopify Order Printer 中可用的 Liquid 變數

可用的類別如下。屬性按照字母順序列出。

訂單

Shopify Order Printer 支援下列訂單屬性:

  • attributes
  • b2b
  • billing_address
  • cancel_reason
  • cancel_reason_label
  • cancelled
  • cancelled_at
  • cart_level_discount_applications
  • checkout_id
  • checkout_payment_collection_url
  • company
  • company_location
  • confirmation_number
  • created_at。訂單已處理的時間。此屬性等同於 GraphQL API 中的 order.processed_at。請使用 date 篩選器格式化時間戳記,例如:{{ order.created_at | date: "%B %e, %Y" }}。
  • customer
  • discounts。已棄用,因為未涵蓋所有折扣類型與細節。order.discounts 屬性已由 order.discount_applications 取代。
  • discounts_amount。已棄用,因為未涵蓋所有折扣類型與細節。order.discounts 屬性已由 order.total_discounts 取代。
  • discount_applications
  • discounts_savings。已棄用,因為未涵蓋所有折扣類型與細節。order.discounts 屬性已由 - 取代。
  • email
  • fees
  • financial_status
  • financial_status_label
  • fulfilled_line_items
  • fulfillment_aborted
  • fulfillment_status
  • fulfillments
  • gateway
  • id
  • item_count
  • landing_site
  • landing_site_ref
  • line_items
  • line_items_subtotal_price
  • location
  • metafields
  • name
  • net_payment
  • note
  • order_name
  • order_number
  • order_status_url
  • payment
  • payment_details
  • po_number
  • refunds
  • requires_shipping
  • shipping_address
  • shipping_method
  • shipping_methods
  • shipping_price
  • shop
  • shop_name
  • subtotal_price
  • tags
  • tax_lines
  • tax_price
  • tip_line_items
  • total_discounts
  • total_duties
  • total_landed_cost_additional_fees
  • total_net_amount
  • total_outstanding
  • total_price
  • total_refunded_amount
  • total_tip
  • transactions
  • unacceptable_risks
  • unfulfilled_line_items
  • unique_gateways
  • user
  • void_transactions

Shop

請參閱以下在 Shopify Order Printer 中可用的 Shop 屬性:

  • accepts_gift_cards
  • account_owner
  • allows_discounts
  • checkout
  • checkout_requires_confirmation_step
  • collections_count
  • contact_information
  • currency
  • customer_accounts_enabled
  • customer_accounts_optional
  • description
  • domain
  • email
  • email_accent_color
  • email_logo_url
  • email_logo_width
  • email_marketing
  • enabled_currencies
  • enabled_locales
  • enabled_payment_types
  • features
  • id
  • latitude
  • legal_notice
  • longitude
  • metafields
  • money_format
  • money_with_currency_format
  • name
  • password_message
  • permanent_domain
  • phone
  • policies
  • privacy_policy
  • products_count
  • refund_policy
  • secure_url
  • shipping_policy
  • subscription_policy
  • terms_of_sale
  • terms_of_service
  • types
  • url

LineItem

請參閱以下在 Shopify Order Printer 中可用的商品項目屬性:

  • aggregated_update
  • applied_discounts。已棄用,因為無法提供所有折扣類型與詳情。line_item.discounts 屬性已由 line_item.discount_allocations 取代。
  • current_quantity
  • discount_allocations
  • discounts。已棄用,因為無法取得所有折扣類型與詳情。請改用 line_item.discount_allocations 以取代 line_item.discounts 屬性。
  • final_line_price
  • final_price
  • fulfillment
  • fulfillment_service
  • gift_card
  • grams
  • groups
  • id
  • image
  • index
  • item_updates
  • json_filter
  • key
  • line_level_discount_allocations
  • line_level_total_discount
  • line_price。已棄用,因為不包含自動折扣與折扣代碼所套用的折扣。請改用 line_item.final_line_price 以取代 line_item.line_price 屬性。
  • message
  • options_with_values
  • original_line_price
  • original_price
  • price。已棄用,因為不包含自動折扣與折扣代碼所套用的折扣。請改用 line_item.final_price 以取代 line_item.price 屬性。
  • product
  • product_id
  • properties
  • quantity
  • refunded_quantity
  • requires_shipping
  • selling_plan_allocation
  • sku
  • successfully_fulfilled_quantity
  • tax_lines
  • taxable
  • title
  • total_discount。已棄用,因為不包含自動折扣與折扣代碼所套用的折扣。請改用 line_item.line_level_total_discount 以取代 line_item.total_discount 屬性。
  • unit_price
  • unit_price_measurement
  • url
  • url_to_remove
  • variant
  • variant_id
  • vendor

出貨作業

請參閱下列在 Shopify Order Printer 可用的出貨作業屬性:

  • created_at。使用 date 篩選器格式化時間戳記,例如可使用 {{ fulfillment.created_at | date: "%B %e, %Y" }}。
  • estimated_delivery_at
  • fulfillment_line_items
  • item_count
  • line_items
  • requires_shipping
  • tracking_company
  • tracking_number
  • tracking_numbers
  • tracking_url
  • tracking_urls
  • updated_at

地址

請參閱下列在 Shopify Order Printer 可用的地址屬性:

  • address1
  • address2
  • city
  • company
  • country
  • country_code
  • country_upper
  • errors
  • first_name
  • id
  • last_name
  • name
  • phone
  • province
  • province_code
  • street
  • summary
  • translated_country_name
  • translated_province_name
  • url
  • zip

顧客

請參閱下列在 Shopify Order Printer 可用的顧客屬性:

  • accepts_marketing
  • account_activation_url
  • addresses
  • addresses_count
  • b2b?
  • default_address
  • email
  • first_name
  • has_account
  • id
  • last_name
  • last_order
  • metafields
  • name
  • new_address
  • orders
  • orders_count
  • payment_methods
  • phone
  • reset_password_url
  • subscribe_url
  • tags
  • tax_exempt
  • total_spent

DiscountApplication

請參閱下列 Shopify Order Printer 可用的 DiscountApplication 屬性:

  • target_selection
  • target_type
  • title
  • total_allocated_amount
  • type
  • value_type
  • value

列印折扣

折扣可套用至整筆訂單或特定商品項目:

  • 訂單層級折扣:套用至整筆訂單。列印訂單發票時,您可以將這些折扣單獨顯示在底部。
  • 商品項目層級折扣:套用至個別品項。在商品項目區塊列印各品項詳情時,您可以註明這些折扣。

您可以使用下列變數存取折扣資訊:

  • 使用 order.total_discounts 值和 order.discount_applications 集合,即可存取套用至訂單或其任一商品項目的所有折扣。
  • 使用 line_item.line_level_total_discount 值或 line_item.line_level_discount_allocations 集合,即可存取商品項目折扣。
  • 使用 line_item.original_price 值可取得套用任何折扣前的商品項目價格。
  • 使用 line_item.final_price 值可取得套用所有相關商品項目層級折扣後的商品項目最終價格。
  • line_item.original_line_price 與 line_item.final_line_price 的值,分別等於 line_item.original_price 與 line_item.final_price 的值乘以 line_item.quantity。
  • 使用 order.cart_level_discount_applications 集合即可存取訂單層級折扣。

列印商品項目層級折扣的範例程式碼區塊:

{% for line_item in order.line_items %}
  <tr>
    <td>{{ line_item.quantity }}</td>
    <td>{{ line_item.title }}
    {% if line_item.line_level_discount_allocations.size > 0 %}
      <span class="subduedText">
        {% for discount_allocation in line_item.line_level_discount_allocations %}
        <br>{{ discount_allocation.discount_application.title }} (-{{ discount_allocation.amount | money }})
        {% endfor %}
      </span>
    {% endif %}
    </td>
    <td style="text-align: right;">
      {% if line_item.original_price != line_item.final_price %}
        <span class="subduedText"><s>{{ line_item.original_price | money }}</s></span>
      {% endif %}
      {{ line_item.final_price | money }}
    </td>
  </tr>
{% endfor %}

列印訂單層級折扣的範例程式碼區塊:

{% for discount_application in order.cart_level_discount_applications %}
<tr>
  <td colspan="2" style="text-align: right;">{% if discount_application.title %}<span class="subduedText">{{ discount_application.title }}</span>{% endif %}</td>
  <td style="text-align: right;">-{{ discount_application.total_allocated_amount | money }}</td>
</tr>
{% endfor %}

DiscountAllocation

請參閱下列 Shopify Order Printer 可用的 DiscountAllocation 屬性:

  • amount
  • discount_application

Discount

請參閱下列 Shopify Order Printer 可用的 Discount 屬性:

  • amount
  • code
  • free_shipping_discount
  • id
  • savings
  • title
  • total_amount
  • total_savings

Product

請參閱下列 Shopify Order Printer 可用的 Product 屬性:

  • as_json
  • available
  • collections
  • compare_at_price
  • compare_at_price_max
  • compare_at_price_min
  • compare_at_price_varies
  • content
  • created_at
  • description
  • featured_image
  • featured_media
  • first_available_variant
  • gift_card?
  • handle
  • has_only_default_variant
  • id
  • images
  • json_filter
  • media
  • metafields
  • object_type
  • options
  • options_by_name
  • options_with_values
  • price
  • price_max
  • price_min
  • price_varies
  • published_at
  • requires_selling_plan
  • selected_or_first_available_selling_plan_allocation
  • selected_or_first_available_variant
  • selected_selling_plan
  • selected_selling_plan_allocation
  • selected_variant
  • selling_plan_groups
  • tags
  • template_suffix
  • title
  • type
  • url
  • variants
  • vendor

子類

請參閱 Shopify Order Printer 提供的下列子類屬性:

  • as_json
  • available
  • barcode
  • compare_at_price
  • featured_image
  • featured_media
  • id
  • image
  • incoming
  • inventory_management
  • inventory_policy
  • inventory_quantity
  • json_filter
  • metafields
  • next_incoming_date
  • option1
  • option2
  • option3
  • options
  • price
  • product
  • requires_selling_plan
  • requires_shipping
  • selected_selling_plan_allocation
  • selling_plan_allocations
  • sku
  • store_availabilities
  • taxable
  • title
  • unit_price
  • unit_price_measurement
  • url
  • weight
  • weight_in_unit
  • weight_unit

退款

請參閱 Shopify Order Printer 提供的下列退款屬性:

  • amount
  • created_at
  • id
  • note
  • refund_line_items
  • restock
  • transactions

運送項目

請參閱 Shopify Order Printer 提供的下列運送項目屬性:

  • handle
  • id
  • original_price
  • price。已棄用,因為該價格未包含訂單層級折扣。shipping_line.price 屬性已由 shipping_line.price_with_discounts 取代。
  • price_with_discounts
  • tax_lines
  • title

稅額項目

請參閱 Shopify Order Printer 提供的下列稅額項目屬性:

  • price
  • rate
  • rate_percentage
  • title

交易

請參閱 Shopify Order Printer 提供的下列交易屬性:

  • amount
  • buyer_pending_payment_instructions
  • buyer_pending_payment_notice
  • created_at
  • gateway
  • gateway_display_name
  • id
  • kind
  • name
  • payment_details
  • receipt
  • show_buyer_pending_payment_instructions
  • status
  • status_label

中繼欄位

附加至父物件的 中繼欄位。 若要瞭解如何在特定物件上存取中繼欄位,請參閱「存取中繼欄位」。

中繼欄位支援多種資料類型,用以決定中繼欄位所儲存的資訊種類。要存取中繼欄位,存取路徑包含兩個層次:

  • 命名空間:將中繼欄位分組以避免衝突,
  • 鍵:中繼欄位名稱。

因此,您可以使用下列語法存取中繼欄位物件:{{ resource.metafields.namespace.key }}。

命名:<object>.metafields.<namespace>.<key>。例如,order.metafields.shipping.express_delivery_status。

類型:

  • String
  • Array:使用 [ ] 作為索引。例如,order.metafield.shipping.express_delivery_status[0]
  • Integer
  • Boolean
  • Date

注意 不支援 Metaobject 類型。

支援中繼欄位的物件:

  • Order
  • Customer
  • Product
  • Variant
  • Location

Shopify Order Printer 可用的 Liquid 過濾器

用法

要對輸出套用過濾器,請在輸出的花括號分隔符號 {{ }} 中,於輸出值後加上管線字元 |,再接過濾器及其參數。以下範例中,product 是物件,title 是其屬性,而 upcase 是所套用的過濾器:

{{ product.title | upcase }}

如果 product.title 的值是 Health potion,則 upcase 過濾器的輸出會是 HEALTH POTION。

如需瞭解如何使用 Liquid 過濾器,請參閱 Shopify 佈景主題 Liquid 參考中的「過濾器章節」。

可套用於 Address 物件的過濾器

  • format_address

如需使用範例,請參閱 Shopify 佈景主題 Liquid 說明文件中的 format_address。

可套用於任何文字或字串的過濾器

  • camelcase
  • camelize
  • encode_url_component
  • format_code
  • handle
  • highlight
  • pad_spaces
  • paragraphize
  • pluralize
  • url_escape
  • url_param_escape

如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 string filters。

適用於金額數值的過濾器

  • money
  • money_with_currency
  • money_without_currency
  • money_without_trailing_zeros

Shopify Order Printer 會使用您在 Shopify 管理介面中為電子郵件通知設定的幣別格式選項來格式化金額。 您可以 change the currency formatting。請在 Shopify 管理介面中設定 Email with currency 與 Email without currency 的值,以變更 Shopify Order Printer 中金額過濾器的格式。

如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 money filters。

用於將物件轉換為 JSON 的過濾器

  • json

如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 json filters。

適用於重量數值的過濾器

  • weight
  • weight_with_unit

如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 weight with unit。

適用於標籤的過濾器

  • highlight_active_tag
  • link_to_add_tag
  • link_to_remove_tag
  • link_to_tag

如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 tag filters。

適用於網址的過濾器

  • article_img_url
  • asset_img_url
  • asset_url
  • cdn_asset_url
  • collection_img_url
  • file_img_url
  • file_url
  • global_asset_url
  • image_url
  • img_tag
  • img_url
  • link_to
  • payment_icon_png_url
  • payment_type_img_url
  • payment_type_svg_tag
  • placeholder_svg_tag
  • product_img_url
  • script_tag
  • shopify_asset_url
  • stylesheet_tag

若需受支援之多媒體檔案篩選器的使用範例,請參閱 Shopify 佈景主題 Liquid 的多媒體檔案篩選器文件。

適用於商品系列的過濾器

  • link_to_type
  • link_to_vendor
  • sort_by
  • url_for_type
  • url_for_vendor
  • within

如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 collection filters。