This guide is intended for advanced users familiar with PHP and WordPress theme files.
Add Custom Information to an Invoice#
You can add customer details or custom order data to a classic PHP invoice template.
First, copy the relevant template files to the active theme's flexible-invoices/documents/ directory, preserving their folder structure. Use a child theme to keep your changes when updating the parent theme. Edit the copied files rather than the originals in the plugin directory.
This method applies to classic PHP templates. It does not add PHP code to templates created with the Gutenberg invoice editor.
Example: Display the Customer's Phone Number#
The customer object available as $client in the buyer template includes a get_phone() method. For invoices created from WooCommerce orders, the plugin uses the order's billing phone number.
To display it in the buyer section, edit the copied documents/invoice/header-parts/buyer.php file. Insert the following code inside the existing table, before its closing </table> tag:
<?php if ( $client->get_phone() ) : ?>
<tr>
<td>
<p>Tel: <?php echo esc_html( $client->get_phone() ); ?></p>
</td>
</tr>
<?php endif; ?>
The row appears only when the document's customer data contains a phone number.
Example: Display a Custom Order Field#
To display a custom field stored as WooCommerce order metadata, load the order linked to the invoice and read the value using get_meta().
The following example can be added to a classic document template where $invoice is available. Place it outside an existing HTML table, or adapt the markup to the surrounding layout:
<?php
$order_id = $invoice->get_order_id();
$invoice_order = $order_id ? wc_get_order( $order_id ) : false;
if ( $invoice_order ) {
$custom_value = $invoice_order->get_meta( '_your_custom_field', true );
if ( is_scalar( $custom_value ) && '' !== (string) $custom_value ) {
echo '<p>Custom reference: ' . esc_html( (string) $custom_value ) . '</p>';
}
}
?>
Replace _your_custom_field with the actual metadata key and change Custom reference to the label you want to display.
This example reads a single text or numeric value from order metadata. It does not create the field or save its value. Documents without a linked order do not display this information.
The value is read from the order when the PDF is generated. If the order metadata changes, a newly generated PDF may display the updated value.
Check Your Changes#
Generate a PDF for an order containing the relevant data, then check a document where the field is empty. Confirm that the content and layout are correct in both cases.
After plugin updates, compare your overridden files with the current plugin templates and apply any necessary compatibility changes.
