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_itemstax_linesfulfillmentstransactionsdiscountsrefundsshipping_methodscustomer
例如,若要存取商品項目變數,您可以使用 line_items 或 order.line_items。
Shopify Order Printer 中可用的 Liquid 變數
可用的類別如下。屬性按照字母順序列出。
訂單
Shopify Order Printer 支援下列訂單屬性:
attributesb2bbilling_addresscancel_reasoncancel_reason_labelcancelledcancelled_atcart_level_discount_applicationscheckout_idcheckout_payment_collection_urlcompanycompany_locationconfirmation_numbercreated_at。訂單已處理的時間。此屬性等同於 GraphQL API 中的order.processed_at。請使用date篩選器格式化時間戳記,例如:{{ order.created_at | date: "%B %e, %Y" }}。customerdiscounts。已棄用,因為未涵蓋所有折扣類型與細節。order.discounts屬性已由order.discount_applications取代。discounts_amount。已棄用,因為未涵蓋所有折扣類型與細節。order.discounts屬性已由order.total_discounts取代。discount_applicationsdiscounts_savings。已棄用,因為未涵蓋所有折扣類型與細節。order.discounts屬性已由-取代。emailfeesfinancial_statusfinancial_status_labelfulfilled_line_itemsfulfillment_abortedfulfillment_statusfulfillmentsgatewayiditem_countlanding_sitelanding_site_refline_itemsline_items_subtotal_pricelocationmetafieldsnamenet_paymentnoteorder_nameorder_numberorder_status_urlpaymentpayment_detailspo_numberrefundsrequires_shippingshipping_addressshipping_methodshipping_methodsshipping_priceshopshop_namesubtotal_pricetagstax_linestax_pricetip_line_itemstotal_discountstotal_dutiestotal_landed_cost_additional_feestotal_net_amounttotal_outstandingtotal_pricetotal_refunded_amounttotal_tiptransactionsunacceptable_risksunfulfilled_line_itemsunique_gatewaysuservoid_transactions
Shop
請參閱以下在 Shopify Order Printer 中可用的 Shop 屬性:
accepts_gift_cardsaccount_ownerallows_discountscheckoutcheckout_requires_confirmation_stepcollections_countcontact_informationcurrencycustomer_accounts_enabledcustomer_accounts_optionaldescriptiondomainemailemail_accent_coloremail_logo_urlemail_logo_widthemail_marketingenabled_currenciesenabled_localesenabled_payment_typesfeaturesidlatitudelegal_noticelongitudemetafieldsmoney_formatmoney_with_currency_formatnamepassword_messagepermanent_domainphonepoliciesprivacy_policyproducts_countrefund_policysecure_urlshipping_policysubscription_policyterms_of_saleterms_of_servicetypesurl
LineItem
請參閱以下在 Shopify Order Printer 中可用的商品項目屬性:
aggregated_updateapplied_discounts。已棄用,因為無法提供所有折扣類型與詳情。line_item.discounts屬性已由line_item.discount_allocations取代。current_quantitydiscount_allocationsdiscounts。已棄用,因為無法取得所有折扣類型與詳情。請改用line_item.discount_allocations以取代line_item.discounts屬性。final_line_pricefinal_pricefulfillmentfulfillment_servicegift_cardgramsgroupsidimageindexitem_updatesjson_filterkeyline_level_discount_allocationsline_level_total_discountline_price。已棄用,因為不包含自動折扣與折扣代碼所套用的折扣。請改用line_item.final_line_price以取代line_item.line_price屬性。messageoptions_with_valuesoriginal_line_priceoriginal_priceprice。已棄用,因為不包含自動折扣與折扣代碼所套用的折扣。請改用line_item.final_price以取代line_item.price屬性。productproduct_idpropertiesquantityrefunded_quantityrequires_shippingselling_plan_allocationskusuccessfully_fulfilled_quantitytax_linestaxabletitletotal_discount。已棄用,因為不包含自動折扣與折扣代碼所套用的折扣。請改用line_item.line_level_total_discount以取代line_item.total_discount屬性。unit_priceunit_price_measurementurlurl_to_removevariantvariant_idvendor
出貨作業
請參閱下列在 Shopify Order Printer 可用的出貨作業屬性:
created_at。使用date篩選器格式化時間戳記,例如可使用{{ fulfillment.created_at | date: "%B %e, %Y" }}。estimated_delivery_atfulfillment_line_itemsitem_countline_itemsrequires_shippingtracking_companytracking_numbertracking_numberstracking_urltracking_urlsupdated_at
地址
請參閱下列在 Shopify Order Printer 可用的地址屬性:
address1address2citycompanycountrycountry_codecountry_uppererrorsfirst_nameidlast_namenamephoneprovinceprovince_codestreetsummarytranslated_country_nametranslated_province_nameurlzip
顧客
請參閱下列在 Shopify Order Printer 可用的顧客屬性:
accepts_marketingaccount_activation_urladdressesaddresses_countb2b?default_addressemailfirst_namehas_accountidlast_namelast_ordermetafieldsnamenew_addressordersorders_countpayment_methodsphonereset_password_urlsubscribe_urltagstax_exempttotal_spent
DiscountApplication
請參閱下列 Shopify Order Printer 可用的 DiscountApplication 屬性:
target_selectiontarget_typetitletotal_allocated_amounttypevalue_typevalue
列印折扣
折扣可套用至整筆訂單或特定商品項目:
- 訂單層級折扣:套用至整筆訂單。列印訂單發票時,您可以將這些折扣單獨顯示在底部。
- 商品項目層級折扣:套用至個別品項。在商品項目區塊列印各品項詳情時,您可以註明這些折扣。
您可以使用下列變數存取折扣資訊:
- 使用
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 %}- 瞭解詳情:折扣類型與在 Liquid 中使用折扣。
DiscountAllocation
請參閱下列 Shopify Order Printer 可用的 DiscountAllocation 屬性:
amountdiscount_application
Discount
請參閱下列 Shopify Order Printer 可用的 Discount 屬性:
amountcodefree_shipping_discountidsavingstitletotal_amounttotal_savings
Product
請參閱下列 Shopify Order Printer 可用的 Product 屬性:
as_jsonavailablecollectionscompare_at_pricecompare_at_price_maxcompare_at_price_mincompare_at_price_variescontentcreated_atdescriptionfeatured_imagefeatured_mediafirst_available_variantgift_card?handlehas_only_default_variantidimagesjson_filtermediametafieldsobject_typeoptionsoptions_by_nameoptions_with_valuespriceprice_maxprice_minprice_variespublished_atrequires_selling_planselected_or_first_available_selling_plan_allocationselected_or_first_available_variantselected_selling_planselected_selling_plan_allocationselected_variantselling_plan_groupstagstemplate_suffixtitletypeurlvariantsvendor
子類
請參閱 Shopify Order Printer 提供的下列子類屬性:
as_jsonavailablebarcodecompare_at_pricefeatured_imagefeatured_mediaidimageincominginventory_managementinventory_policyinventory_quantityjson_filtermetafieldsnext_incoming_dateoption1option2option3optionspriceproductrequires_selling_planrequires_shippingselected_selling_plan_allocationselling_plan_allocationsskustore_availabilitiestaxabletitleunit_priceunit_price_measurementurlweightweight_in_unitweight_unit
退款
請參閱 Shopify Order Printer 提供的下列退款屬性:
amountcreated_atidnoterefund_line_itemsrestocktransactions
運送項目
請參閱 Shopify Order Printer 提供的下列運送項目屬性:
handleidoriginal_priceprice。已棄用,因為該價格未包含訂單層級折扣。shipping_line.price屬性已由shipping_line.price_with_discounts取代。price_with_discountstax_linestitle
稅額項目
請參閱 Shopify Order Printer 提供的下列稅額項目屬性:
priceraterate_percentagetitle
交易
請參閱 Shopify Order Printer 提供的下列交易屬性:
amountbuyer_pending_payment_instructionsbuyer_pending_payment_noticecreated_atgatewaygateway_display_nameidkindnamepayment_detailsreceiptshow_buyer_pending_payment_instructionsstatusstatus_label
中繼欄位
附加至父物件的 中繼欄位。 若要瞭解如何在特定物件上存取中繼欄位,請參閱「存取中繼欄位」。
中繼欄位支援多種資料類型,用以決定中繼欄位所儲存的資訊種類。要存取中繼欄位,存取路徑包含兩個層次:
- 命名空間:將中繼欄位分組以避免衝突,
- 鍵:中繼欄位名稱。
因此,您可以使用下列語法存取中繼欄位物件:{{ resource.metafields.namespace.key }}。
命名:<object>.metafields.<namespace>.<key>。例如,order.metafields.shipping.express_delivery_status。
類型:
StringArray:使用[ ]作為索引。例如,order.metafield.shipping.express_delivery_status[0]IntegerBooleanDate
注意 不支援 Metaobject 類型。
支援中繼欄位的物件:
OrderCustomerProductVariantLocation
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。
可套用於任何文字或字串的過濾器
camelcasecamelizeencode_url_componentformat_codehandlehighlightpad_spacesparagraphizepluralizeurl_escapeurl_param_escape
如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 string filters。
適用於金額數值的過濾器
moneymoney_with_currencymoney_without_currencymoney_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。
適用於重量數值的過濾器
weightweight_with_unit
如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 weight with unit。
適用於標籤的過濾器
highlight_active_taglink_to_add_taglink_to_remove_taglink_to_tag
如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 tag filters。
適用於網址的過濾器
article_img_urlasset_img_urlasset_urlcdn_asset_urlcollection_img_urlfile_img_urlfile_urlglobal_asset_urlimage_urlimg_tagimg_urllink_topayment_icon_png_urlpayment_type_img_urlpayment_type_svg_tagplaceholder_svg_tagproduct_img_urlscript_tagshopify_asset_urlstylesheet_tag
若需受支援之多媒體檔案篩選器的使用範例,請參閱 Shopify 佈景主題 Liquid 的多媒體檔案篩選器文件。
適用於商品系列的過濾器
link_to_typelink_to_vendorsort_byurl_for_typeurl_for_vendorwithin
如需使用範例,請參閱 Shopify 佈景主題的 Liquid 說明文件中的 collection filters。