Override url opened by button “View Invoice”
The Phone Orders for WooCommerce plugin provides a dedicated “View Invoice” button after an order is created (or later, when viewing an existing order). By default, the button leads to WooCommerce’s native order‑details page, which may not include a branded invoice layout provided by third‑party invoicing plugins. This guide explains how to customise the URL opened by that button, ensuring it points directly to your preferred invoice‑generating endpoint.
Before applying the code, complete the following steps:
- Install Phone Orders for WooCommerce (Pro version recommended for access to all invoice‑related settings).
- Enable the “View Invoice” button via the plugin’s interface (Navigate to WooCommerce → Phone Orders → Settings in your WordPress admin area)
- Have a functioning invoice plugin installed and activated (e.g., Booster Plus for WooCommerce, PDF Invoices, or any other plugin that creates invoices and provides a dedicated URL).
The Solution: Modify the Invoice URL with a PHP Filter
The Phone Orders plugin provides a dedicated filter hook, wpo_view_invoice_url, which allows you to change the URL opened by the “View Invoice” button. This filter receives two parameters:
| Parameter | Type | Description |
|---|---|---|
$invoice_url | string | The default URL (pointing to the WooCommerce order details page). |
$order_id | int | The ID of the order for which the invoice should be generated. |
Your custom function must return the new invoice URL.
The following example for the Booster Plus plugin:
|
1 2 3 4 5 6 7 8 9 10 |
add_filter( 'wpo_view_invoice_url', function ( $invoice_url, $order_id ) { return add_query_arg( array( 'order_id' => $order_id, 'invoice_type_id' => 'invoice', 'get_invoice' => '1', ), get_home_url() ); }, 10, 2 ); |
What this code does:
| Part | Explanation |
|---|---|
add_filter('wpo_view_invoice_url', ... ) | Attaches your custom function to the wpo_view_invoice_url filter. |
function ( $invoice_url, $order_id ) { ... } | Your callback receives the default URL and the order ID. |
add_query_arg( array(...), get_home_url() ) | Builds a URL with the required query parameters (order_id, invoice_type_id, get_invoice). |
return ... | Returns the modified URL, overriding the default value. |
You have two safe options for adding custom PHP code:
- Option A (Recommended): Use the free Code Snippets plugin. This is the safest method. It allows you to add, activate, and deactivate snippets without touching your theme files.
- Option B: Add to your child theme’s
functions.phpfile. If you are comfortable editing theme files, add the code to your active child theme’sfunctions.php. Never add custom code directly to a parent theme, as it will be lost when the theme is updated.