跳到主内容
版本: 1.x

收据数据参考

WCPOS 无逻辑 HTML 模板和热敏 XML 模板从相同的规范收据数据渲染。使用 Mustache 点路径,如 {{order.number}}{{store.name}}{{totals.total_display}}。数组通过区块渲染:

{{#lines}}
{{name}} x {{qty}} — {{line_total_display}}
{{/lines}}

规范契约由服务器端的 WCPOS 收据数据构建器生成,并由应用中的离线收据渲染器镜像。收据会立即从本地数据打开,然后在服务器响应可用时升级为服务器数据,因此自定义模板应使用以下字段,而非 PHP 订单方法。

渲染规则

货币字段

数值型金额字段保留为数字,渲染器会添加支持本地化的 _display 字段用于模板输出:

数值字段显示字段
totals.totaltotals.total_display
lines[].line_totallines[].line_total_display
payments[].amountpayments[].amount_display
tax_summary[].tax_amounttax_summary[].tax_amount_display

打印收据时优先使用 _display 字段。仅在条件判断或机器可读输出中使用数值字段。

税额显示感知字段

多个字段提供了含税和不含税变体,以及一个显示端的便捷值。该便捷值遵循店铺的购物车税额显示设置。

便捷字段含税字段不含税字段
lines[].unit_pricelines[].unit_price_incllines[].unit_price_excl
lines[].unit_subtotallines[].unit_subtotal_incllines[].unit_subtotal_excl
lines[].line_subtotallines[].line_subtotal_incllines[].line_subtotal_excl
lines[].discountslines[].discounts_incllines[].discounts_excl
lines[].line_totallines[].line_total_incllines[].line_total_excl
fees[].totalfees[].total_inclfees[].total_excl
shipping[].totalshipping[].total_inclshipping[].total_excl
discounts[].totaldiscounts[].total_incldiscounts[].total_excl
totals.subtotaltotals.subtotal_incltotals.subtotal_excl
totals.discount_totaltotals.discount_total_incltotals.discount_total_excl
totals.totaltotals.total_incltotals.total_excl

日期对象

日期字段是包含多种预格式化变体的对象。这样可以避免在 Mustache 中进行日期格式化。

字段说明
datetimedatetime默认日期/时间字符串
datetime_shortdatetime_longdatetime_full本地化的组合格式
date_shortdate_longdate_full区域感知的纯日期格式
date_ymddate_dmydate_mdy固定顺序的日期格式
weekday_shortweekday_long星期名称
daymonthmonth_shortmonth_longyear单独的日期部分

可用的日期对象:order.createdorder.paidorder.completedorder.printedrefunds[].dateorder.printed 在渲染时会刷新,适用于重新打印的场景。

顶级部分

部分类型描述
orderobject订单标识、状态、日期、备注和付款 URL 信息
storeobject店铺标识、地址、联系方式、税号、Logo、营业时间和页脚文本
cashierobject处理订单的用户
customerobject客户显示名称、地址和税号
linesarray商品行项目
feesarray费用行
shippingarray运费行
discountsarray优惠券/折扣行
totalsobject订单合计、支付合计、退款摘要及项目数量
taxobject用于区块条件判断的税费显示模式标志
tax_summaryarray按税率汇总的税费行
has_tax_summarybooleantax_summary 的便捷判断标志
paymentsarray支付行
refundsarray应用于该订单的退款记录
fiscalobject由财税集成填充的财税快照字段
presentation_hintsobject格式化与渲染器提示
i18nobject内置和自定义模板的翻译标签

order

字段类型示例/说明
order.idnumber1234
order.numberstring面向用户的订单编号,例如 "10045"
order.currencystringISO 货币代码,例如 "USD"
order.customer_notestring客户/订单备注
order.wc_statusstringWooCommerce 原始状态标识,例如 "processing"
order.status_labelstring本地化的状态标签,包含自定义状态
order.created_viastring来源/渠道,例如 "woocommerce-pos"
order.needs_paymentboolean是否应显示付款部分
order.payment_urlstring订单付款 URL(可用时)
order.createddate object订单创建日期
order.paiddate object付款日期,未付款时为空字符串
order.completeddate object完成日期,未完成时为空字符串
order.printeddate object渲染时的打印/重新打印时间戳

店铺

字段类型示例/说明
store.idnumber店铺 ID,已删除店铺显示历史 ID
store.namestring店铺显示名称
store.address.address_1string街道地址第 1 行
store.address.address_2string门牌号/单元行
store.address.citystring城市/地区
store.address.statestring州/省
store.address.postcodestring邮政编码
store.address.countrystringISO 国家代码
store.address_linesarray预格式化的地址行;推荐在大多数模板中使用
store.tax_idsarray结构化的企业税号;建议循环遍历此数组,而非使用单个税号
store.phonestring店铺电话
store.emailstring店铺邮箱
store.logostring/null店铺 Logo URL 或 data URI
store.opening_hoursstring/null紧凑格式的营业时间文本
store.opening_hours_verticalstring/null多行格式的营业时间
store.opening_hours_inlinestring/null逗号分隔的营业时间文本
store.opening_hours_notesstring/null营业时间备注(自由文本)
store.personal_notesstring/null小票页脚/个人备注
store.policies_and_conditionsstring/null退款、退货或条款文本
store.footer_imprintstring/null法律页脚印记

税号对象

store.tax_idscustomer.tax_ids 包含具有相同结构的对象:

字段类型描述
typestring标识符,例如 eu_vatde_steuernummerau_abnbr_cpfus_einother
valuestring要打印的税号值
countrystring/null已知时的 ISO 国家代码
labelstring/null本地化显示标签,在渲染前解析

示例:

{{#store.tax_ids}}
{{label}}: {{value}}
{{/store.tax_ids}}

cashier

字段类型示例/说明
cashier.idnumberWordPress 用户 ID,未知时为 0
cashier.namestring收银员显示名称

customer

字段类型示例/说明
customer.idnumber/null客户 ID,访客时为 null
customer.namestring客户显示名称,或访客标签
customer.billing_address.*objectWooCommerce 账单地址字段
customer.shipping_address.*objectWooCommerce 收货地址字段
customer.tax_idsarray从订单快照中获取的客户税号结构化数据

常用地址键包括 first_namelast_namecompanyaddress_1address_2citystatepostcodecountryemailphone

lines

使用 {{#lines}}...{{/lines}} 进行循环。

字段类型描述
keystring稳定的行键/订单项 ID
skustring产品 SKU
namestring产品或行项目显示名称
qtynumber销售数量
qty_refundednumber该行项目的退款数量
unit_subtotal / _incl / _exclnumber折扣前单价
unit_price / _incl / _exclnumber折扣后单价
line_subtotal / _incl / _exclnumber折扣前行小计
discounts / _incl / _exclnumber折扣金额(正值)
line_total / _incl / _exclnumber最终行合计
total_refundednumber该行的退款总额(正值)
taxesarray该行按税率分列的税额行
metaarray订单项元数据,以 {key, value} 键值对形式表示
attributesarray商品/变体属性,以 {key, value} 键值对形式表示

格式化变体包括 unit_subtotal_displayunit_price_displayline_subtotal_displaydiscounts_displayline_total_display,以及含税/不含税的 _display 变体。

费用和运费

使用 {{#fees}}...{{/fees}}{{#shipping}}...{{/shipping}} 进行循环遍历。

字段类型描述
labelstring费用标签或配送方式名称
method_idstring配送方式 ID(仅限配送)
total / _incl / _exclnumber显示端金额、含税金额和不含税金额
taxesarray按税率分列的税额行
metaarray{key, value} 元数据键值对

格式化变体:total_displaytotal_incl_displaytotal_excl_display

discounts

使用 {{#discounts}}...{{/discounts}} 进行循环。

字段类型描述
labelstring优惠券描述或代码回退值
codestring优惠券代码
codesstring旧版/显示回退值,用于拼接的代码
total / _incl / _exclnumber折扣金额,为正数值

格式化变体:total_displaytotal_incl_displaytotal_excl_display。如果需要将折扣显示为负数行,请在模板中自行添加负号。

totals

字段类型描述
totals.subtotal / _incl / _exclnumber折扣前的订单小计
totals.discount_total / _incl / _exclnumber订单折扣总额,为正数值
totals.tax_totalnumber税额合计
totals.total / _incl / _exclnumber订单总计
totals.paid_totalnumber已支付/已抵扣金额
totals.change_totalnumber找零给顾客的金额
totals.refund_totalnumber退款总额(正值)
totals.net_totalnumbertotal - refund_total,最小值为零
totals.total_qtynumber商品行数量总和
totals.line_countnumber商品行数

格式化变体包括 subtotal_displaydiscount_total_displaytax_total_displaytotal_displaypaid_total_displaychange_total_displayrefund_total_displaynet_total_display,以及适用情况下的含税/不含税变体。

tax 和 tax_summary

使用 tax 进行显示模式判断,使用 tax_summary 显示分项税率行。

税费字段类型描述
tax.displaystringinclexcl
tax.display_inclboolean当价格显示为含税时为 true
tax.display_exclboolean当价格显示为不含税时为 true
tax.breakdownstringhiddensingleitemized
tax.breakdown_hiddenboolean当应隐藏税项行时为 true
tax.breakdown_singleboolean当优先显示单一税额合计时为 true
tax.breakdown_itemizedboolean当优先显示按税率逐项列出时为 true
has_tax_summarybooleantax_summary 包含行数据时为 true

使用 tax_summary 循环遍历 {{#tax_summary}}...{{/tax_summary}}

字段类型描述
codestring税率 ID/代码
ratenumber/null解析后的税率百分比
labelstring税率标签
compoundboolean是否为复合税率
taxable_amount_exclnumber/null不含税应税基数
tax_amountnumber已征税额
taxable_amount_inclnumber/null含税应税基数

格式化变体:taxable_amount_excl_displaytax_amount_displaytaxable_amount_incl_display

payments

使用 {{#payments}}...{{/payments}} 进行循环。

字段类型描述
method_idstring支付方式标识符
method_titlestring支付方式显示名称
amountnumber应用于订单的金额
transaction_idstring支付网关交易 ID
tenderednumber存在时为收到的现金金额
changenumber存在时为找零金额

格式化变体:amount_displaytendered_displaychange_display

退款

使用 {{#refunds}}...{{/refunds}} 进行循环。退款金额为正数绝对值;模板自行决定是否添加负号或渲染单独的退货商品区块。

字段类型描述
idnumber退款记录 ID
datedate object退款创建日期
amountnumber退款总额
subtotalnumber退款行小计
tax_totalnumber退款税额
shipping_totalnumber退款运费金额
shipping_taxnumber退款运费税额
reasonstring退款原因
refunded_by_idnumber/null发起退款的用户 ID
refunded_by_namestring发起退款的用户显示名称
refunded_paymentboolean是否通过支付网关退款
destinationstringoriginal_methodcashmanual
gateway_idstring用于退款的支付网关 ID
gateway_titlestring支付网关显示名称
processing_modestring服务商/手动处理模式
linesarray退款商品行
feesarray退款费用行
shippingarray退款运费行

退款行字段包括 nameskuqtytotaltotal_incltotal_exclline_totalunit_totaltaxes。退款费用行和运费行使用 labeltotaltotal_incltotal_excltaxes。总计和税额会添加显示变体。

fiscal

财务字段默认为空,由财务集成或 WCPOS Pro 快照增强功能填充。

字段类型描述
fiscal.immutable_idstring不可变财务标识符
fiscal.receipt_numberstring财务收据编号
fiscal.sequencenumber/null序列计数器
fiscal.hashstring哈希/签名值
fiscal.qr_payloadstring财务验证二维码数据
fiscal.tax_agency_codestring税务机关代码
fiscal.signed_atstring财务签名时间戳
fiscal.signature_excerptstring用于显示的截断签名
fiscal.document_labelstring单据标签,例如 Tax Invoice
fiscal.is_reprintboolean此次渲染是否为重新打印
fiscal.reprint_countnumber重新打印次数
fiscal.extra_fieldsarray/object特定辖区的值

presentation_hints

这些字段主要由渲染器和格式化器使用。需要时可在模板中使用。

字段类型描述
presentation_hints.display_taxstringinclexclhiddenitemizedsingle
presentation_hints.prices_entered_with_taxboolean商品目录价格是否含税
presentation_hints.rounding_modestringWooCommerce 税额取整设置
presentation_hints.localestring用于格式化的区域设置
presentation_hints.timezonestring收据时区
presentation_hints.currency_positionstring货币符号位置
presentation_hints.currency_symbolstring货币符号
presentation_hints.price_thousand_separatorstring千位分隔符
presentation_hints.price_decimal_separatorstring小数分隔符
presentation_hints.price_num_decimalsnumber小数位数
presentation_hints.price_display_suffixstringWooCommerce 价格显示后缀
presentation_hints.order_barcode_typestring图库模板使用的条形码类型

i18n

尽可能使用 i18n 标签,而不是硬编码文本:

{{i18n.order}} #{{order.number}}
{{i18n.cashier}}: {{cashier.name}}
{{i18n.total}}: {{totals.total_display}}

常用键包括 orderdatecashiercustomeritemskuqtyunit_pricediscountsubtotaltotaltaxpaidtenderedchangetax_summaryrefundednet_totalcustomer_notethank_you_purchaseopening_hours,以及税号标签键,如 store_tax_id_label_eu_vatcustomer_tax_id_label_other。扩展可能会添加额外的键。