Product Icon

Xero for WooCommerce

Trending
Save time with automated sync between WooCommerce and your Xero account.

Filter for Xero reference code

I would like to request the addition of a filter hook to allow customization of the invoice reference pieces in the Xero invoice XML output.

Location:
/includes/class-wc-xr-invoice.php – Line 420 in the to_xml() method

Current Behavior:
The invoice reference is currently hardcoded to include payment method, transaction ID, and order number, with no way to customize or override these values.

Proposed Change:
Add a filter hook that allows developers to modify the $reference_pieces array before it’s compiled into the XML reference field:

$reference_pieces = apply_filters( ‘woocommerce_xero_invoice_reference_pieces’, $reference_pieces, $order, $this );

Use Case:

This would allow merchants to use custom reference formats (such as purchase order numbers) in their Xero invoices without modifying the plugin directly.

Example Usage:

add_filter( ‘woocommerce_xero_invoice_reference_pieces’, function( $reference_pieces, $order, $invoice ) {
$po_number = get_post_meta( $order->get_id(), ‘purchase_order_number’, true );
if ( ! empty( $po_number ) ) {
$reference_pieces = array( esc_xml( $po_number ) );
}
return $reference_pieces;
}, 10, 3 );

This is a non-breaking change that maintains backward compatibility while providing extensibility for custom implementations.

Author

Pat Wilkinson

Current Status

Open

Last updated: January 30, 2026

0 comments

Log in to comment on this feature request.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.