---
title: How to Add Conditional Content and Item Loops to PDF Invoices
description: Make one WooCommerce PDF invoice template adapt to each order with line item and refund loops and conditions.
url: "https://wpfactory.com/docs/conditional-content-in-pdf-invoices/"
updated: "2026-10-05"
category: How to
---

# How to Add Conditional Content and Item Loops to PDF Invoices

To add loops and conditions to PDF invoices in PDF Invoices & Packing Slips Generator for WooCommerce, edit the document's HTML content field under WPFactory > PDF Invoicing. Wrap rows in [each_item] to loop over line items, use [each_refund] for refunds, and use [if] with value1, operator, and value2 to show content only when a test passes.

Edit these in the **HTML content** field of the document, under **WPFactory > PDF Invoicing** (also reachable at **WooCommerce > Settings > PDF Invoicing**).

![Invoice document HTML content editor](https://wpfactory.com/wp-content/uploads/Doc-Invoice-Options-Content-Options.png)

### Loop over line items

Wrap a template row in `[each_item]` ... `[/each_item]`. The item shortcodes inside resolve for each product on the order.

```
[each_item]
<tr>
  <td>[item_name]</td>
  <td>[item_qty]</td>
  <td>[item_total format="price"]</td>
</tr>
[/each_item]
```

Useful `[each_item]` attributes: `type` (comma-separated list of `line_item`, `fee`, `shipping`, `tax`, `coupon`; default `line_item`), `product_id` (limit to certain products), and `before`/`after` (markup added only when at least one item matches).

### Loop over refunds

Use `[each_refund]` ... `[/each_refund]` with the refund shortcodes `[refund_nr]`, `[refund_total]`, and `[refund_reason]`:

```
[each_refund]
<p>Refund [refund_nr]: [refund_total format="price"] - [refund_reason]</p>
[/each_refund]
```

### Show content conditionally

The `[if]` shortcode compares two values and outputs its contents only when the test passes. It requires `value1`, `operator`, and `value2`. Use curly braces around nested shortcodes inside the attributes.

```
[if value1="{order_shipping_total}" operator="greater" value2="0"]
<p>Shipping: [order_shipping_total format="price"]</p>
[/if]
```

Supported operators: `equal`, `not_equal`, `less`, `less_or_equal`, `greater`, `greater_or_equal`.

**Note:** inside `[if]` attributes, write nested shortcodes with curly braces (`{order_total}`), which the plugin converts to square brackets before evaluating. Item shortcodes such as `[item_name]` only return a value inside an `[each_item]` loop.

### Layout helpers

- `[line]`: a horizontal rule in the document's line color.
- `[clear]`: an empty paragraph to add vertical space.
- `[break]`: a single line break.
- `[page_break]`: starts a new page.
- `[paragraph]` ... `[/paragraph]`: wraps content in a paragraph.

### Use cases

- Show a "Shipping" line only when the order was shipped.
- List refunds on a credit note.
- Print a fees or taxes table by passing `type` to `[each_item]`.

### Get more control

The template engine is free. [PDF Invoices & Packing Slips Generator for WooCommerce](https://wpfactory.com/item/pdf-invoicing-for-woocommerce/) Pro lets you build distinct templates for multiple document types. [See what Pro unlocks](https://wpfactory.com/item/pdf-invoicing-for-woocommerce/).

Related articles

- [How to Add a Page Background or Watermark to PDF Invoices](https://wpfactory.com/docs/pdf-page-background-and-watermark/)
- [How to Add a Logo, Header, and Footer to PDF Invoices](https://wpfactory.com/docs/add-logo-header-footer-to-pdf-invoices/)
- [Let Customers Download PDF Invoices from My Account](https://wpfactory.com/docs/woocommerce-pdf-invoices-my-account/)
- [How to Create Multilingual PDF Invoices](https://wpfactory.com/docs/multilingual-pdf-invoices/)
- [How to Create and Manage PDF Invoices for WooCommerce Orders](https://wpfactory.com/docs/create-manage-woocommerce-pdf-invoices/)
