North Packing Slips & Invoices hooks
You can change how documents look, add your own print buttons and use invoice data in other systems.
Your own template
Copy a template into your theme and change it there. The plugin uses your copy automatically.
| Document | Copy from | To |
|---|---|---|
| Packing slip | templates/minimal/packing-slip.php | yourtheme/print-packing-slips-invoices/minimal/packing-slip.php |
| Invoice | templates/minimal/invoice.php | yourtheme/print-packing-slips-invoices/minimal/invoice.php |
The templates Classic and Compact use the same markup as Minimal with different styling. To change one of them only, put your copy in a folder with its name, for example yourtheme/print-packing-slips-invoices/compact/.
Each template receives two arrays: $doc with the document’s data (title, addresses, items) and $shop with the shop details from the plugin settings (company name, address, logo).
print_packing_slips_invoices_template_path (filter)
Chooses another template file, for example one shipped by your own plugin.
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the template |
$template | string | Template slug: minimal, classic or compact |
$type | string | Document type: packing-slip or invoice |
Print buttons from your own plugin
Check that the plugin is active with function_exists() first. There is no dependency in either direction.
print_packing_slips_invoices_url( $order_ids, $type = 'packing-slip' )
Returns the URL of the print page for one or more orders, or '' if the current user may not print. Escape it with esc_url().
Note: an invoice link creates the invoice, and uses an invoice number, the first time it is opened.
if ( function_exists( 'print_packing_slips_invoices_url' ) ) {
$url = print_packing_slips_invoices_url( $order->get_id() );
if ( $url ) {
printf( '<a class="button" href="%s" target="_blank">%s</a>', esc_url( $url ), esc_html__( 'Packing slip', 'my-plugin' ) );
}
}
print_packing_slips_invoices_invoice_number( $order )
Returns the order’s invoice number, or '' if no invoice has been created.
Events and data
print_packing_slips_invoices_loaded (action)
Fires when the plugin is ready. The public functions above are available from here on.
print_packing_slips_invoices_invoice_created (action)
Fires after an invoice has been created. Use it to send the invoice to an accounting system.
| Parameter | Type | Description |
|---|---|---|
$snapshot | array | The invoice data as it was stored, including the number |
$order | WC_Order | The order |
The snapshot is fixed when the invoice is created. Later changes to the order do not change the invoice.
print_packing_slips_invoices_buyer_vat_number (filter)
Changes the buyer’s VAT number printed on the invoice, for example when your checkout stores it in a custom field.
| Parameter | Type | Description |
|---|---|---|
$value | string | The VAT number |
$order | WC_Order | The order |
add_filter( 'print_packing_slips_invoices_buyer_vat_number', function ( string $value, WC_Order $order ) {
return $value ?: (string) $order->get_meta( '_billing_vat_number' );
}, 10, 2 );
