> ## Documentation Index
> Fetch the complete documentation index at: https://foliant-help.iforiti.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 範本中的商品項目

> 在 Liquid 中循環處理訂單的商品項目，並列印其標題、數量、價格、SKU、圖片、重量和屬性。

訂單上的商品位於 `line_items` 中。若要列印這些商品，請循環處理此清單：`{% for line_item in line_items %}` 與 `{% endfor %}` 之間的所有內容會針對每個商品重複一次，而 `line_item` 就是目前的商品。商品項目欄位只能在迴圈內使用。

## 基本商品表格

```liquid theme={null}
<table>
  {% for line_item in line_items %}
    <tr>
      <td>{{ line_item.title }}</td>
      <td>{{ line_item.sku }}</td>
      <td>{{ line_item.quantity }}</td>
      <td>{{ line_item.price | money }}</td>
      <td>{{ line_item.line_price | money }}</td>
    </tr>
  {% endfor %}
</table>
```

## 商品項目欄位

| 變數 | 列印內容 |
| - | - |
| `line_item.title` | 商品的標題（產品和子類） |
| `line_item.name` | 商品的名稱 |
| `line_item.product_title` | 產品的標題 |
| `line_item.variant_title` | 子類的標題，例如「Blue / Large」 |
| `line_item.quantity` | 訂購數量，包含已退款的商品 |
| `line_item.fulfillable_quantity` | 尚待出貨的數量 |
| `line_item.refunded_quantity` | 已退款的數量 |
| `line_item.sku` | SKU |
| `line_item.vendor` | 廠商 |
| `line_item.price` | 套用商品項目折扣後的單價（分） |
| `line_item.original_price` | 折扣前的單價（分） |
| `line_item.line_price` | 商品項目總計：單價 × 數量，套用商品項目折扣後（分） |
| `line_item.total_discount` | 商品項目的折扣（分） |
| `line_item.discount_per_item` | 每件商品的折扣（分） |
| `line_item.total_tax` | 商品項目的稅金（分） |
| `line_item.cost` | 商品的成本，用於採購單（分） |
| `line_item.tax_lines` | 商品項目的稅金：循環處理以取得 `title`、`rate`、`price` |
| `line_item.discount_allocations` | 套用於商品項目的折扣：循環處理以取得 `amount` |
| `line_item.properties` | 商品項目屬性。請參閱[訂單屬性和商品項目屬性](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-custom-fields.md)。 |
| `line_item.hs_tariff_code` | HS 關稅代碼 |
| `line_item.country_of_origin` | 原產國 |
| `line_item.weight` | 單件商品的重量，以其本身的單位表示 |
| `line_item.grams` | 單件商品的重量，以公克表示；`{{ line_item.grams \| weight_with_unit }}` 會加上單位 |
| `line_item.total_weight` | 商品項目的重量（商品 × 數量） |
| `line_item.image` | 商品的圖片；`{{ line_item.image \| img_url: 'thumb' \| img_tag }}` 會列印圖片 |
| `line_item.requires_shipping` | 商品是否需要運送 |
| `line_item.gift_card` | 商品是否為禮品卡 |
| `line_item.product` | 產品（`title`、`type`、`vendor`、`tags`、`handle`…） |
| `line_item.variant` | 子類（`title`、`sku`、`barcode`、`option1`、`inventory_quantity`…） |

## 常見寫法

僅在有子類標題時，將其列印在產品下方：

```liquid theme={null}
{{ line_item.product_title }}
{% if line_item.variant_title != blank %}<br>{{ line_item.variant_title }}{% endif %}
```

在裝箱單上略過已全額退款的商品：

```liquid theme={null}
{% for line_item in line_items %}
  {% if line_item.quantity > line_item.refunded_quantity %}
    {{ line_item.title }} × {{ line_item.quantity | minus: line_item.refunded_quantity }}
  {% endif %}
{% endfor %}
```

顯示每個 SKU 的條碼：

```liquid theme={null}
{{ line_item.sku | barcode }}
```

## 每批出貨一份文件

當範本為每批出貨列印一份文件時（範本設定頁面上的 **分批出貨**），`document_fulfillment` 就是正在列印的那批出貨。若只要列出其中的商品：

```liquid theme={null}
{% if document_fulfillment %}
  {% assign line_items = document_fulfillment.line_items %}
{% endif %}
```

## 注意事項

* 價格以分為單位：請務必使用金額篩選器列印。請參閱[範本中的金額和幣別](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-money-and-currency.md)。
* 商品圖片會以您透過 `img_url` 指定的尺寸列印，例如 `'thumb'`、`'small'`、`'medium'` 或 `'120x120'`。
* 產品和子類的中繼欄位位於 `line_item.product.metafields` 和 `line_item.variant.metafields` 之下。請參閱[範本中的中繼欄位](https://foliant-help.iforiti.com/zh-Hant/template-editor/metafields.md)。
* 迴圈變數名稱可由您自行決定，但 `line_item` 與參考資料和起始範本一致。
* 來自 Bold Product Options 和 Infinite Options 的訂單會新增 `line_item.options`, `line_item.option_addon`, `line_item.option_addons` 以及包含加購項目的價格，因此您可以將付費加購項目列印在所屬品項下方。請參閱 [商品選項應用程式（Bold、Infinite Options）](https://foliant-help.iforiti.com/zh-Hant/templates/product-options-apps.md)。

## 相關文章

* [訂單物件和常用變數](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-order-variables.md)
* [範本中的金額和幣別](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-money-and-currency.md)
* [訂單屬性和商品項目屬性](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-custom-fields.md)
* [範本中的中繼欄位](https://foliant-help.iforiti.com/zh-Hant/template-editor/metafields.md)
* [商品選項應用程式（Bold、Infinite Options）](https://foliant-help.iforiti.com/zh-Hant/templates/product-options-apps.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.