Manipulate Invoices
do_action( 'vikbooking_before_generate_invoice', array $booking, array &$invoice_args )
Fires before generating an invoice for a reservation.
Description
Plugins can use this filter to manipulate at runtime certain aspects of the invoice being generated in PDF format.
Please note this is not meant to edit the layout of the invoice, there's an apposite template for that.
Parameters
- $booking
-
(array) The booking record for which the invoice is being generated.
- &$invoice_args
-
(array) The values of the invoice that can be manipulated.
This is how the hook will fire. In order to manipulate (modify) data about the invoice (number, suffix, date, company details, translation on/off etc..) it is necessary to modify the properties of the array passed by reference.
Example
The example below shows how to quickly manipulate some aspects of the PDF invoice.
/**
* Triggers an action to manipulate certain aspects of the invoice before it gets generated.
*
* @param array $booking the booking record for which the invoice is being generated.
* @param array &$invoice_args the values of the invoice that can be manipulated.
*
* @return void the array $invoice_args is passed by reference and can be modified.
*/
add_action('vikbooking_before_generate_invoice', function($booking, &$invoice_args) {
if (!is_array($invoice_args) || !$invoice_args) {
// some other plugins may have unset the invoice arguments array
return;
}
// modify at runtime the invoice suffix by adding the booking ID
if (is_array($booking) && !empty($booking['id'])) {
$invoice_args['invoice_suff'] = "/ID-{$booking['id']}";
}
// turn on the translation flag to always translate the invoices into the booking language
$invoice_args['translate'] = true;
}, 10, 3);
Changelog
Version | Description |
---|---|
1.6 | Introduced. |
Last Update: 2023-06-13
Helpful?
100% of people found this helpful.