English (United Kingdom)
Knowledge Base  >  Vik Booking  >  For Developers  >  Manipulate Invoices
1.6

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.

This website uses cookies

This website uses cookies and similar technologies. Some of these technologies are necessary for the proper functioning of the website (Essential). Other technologies are used to evaluate user behavior (Analysis), to integrate external media or for advertising purposes. If you agree, these technologies are activated. For details, please refer to the privacy policy. From this same page you can also update/revoke your consent. If you do not give your consent, only cookies with essential functions will be activated.

We use technologies from the USA on our website. If you give your consent, you therefore consent at the same time to your data being transferred to the USA. We would like to point out that the USA does not have a level of data protection comparable to that of the EU and that any US company can be obliged by state authorities to hand over your data without you having any effective legal protection against this.