Developers - Filter Reference

WooCommerce PDF Invoice comes with several filter hooks that allow developers to extend functionality.

 

woo_pdf_generate_regular_invoice

Filter hook called just before generating regular invoice when order is being marked as completed. Simply return false from your callback function to cancel generating invoice.

Parameters: 

$proceed bool whether to proceed generating invoice or not
$order object current order object

 

woo_pdf_send_by_email

Filter hook called just before attaching PDF invoice to one of standard WooCommerce emails. Simply return false from your callback function to cancel generating invoice.

Parameters: 

$proceed bool whether to proceed generating invoice or not
$order object current order object
$email_type string WooCommerce email type, e.g. "customer_completed_order"

 

woo_pdf_allow_regular_invoice_download

Filter hook called just before displaying regular invoice download link or download button. Simply return false from your callback function to cancel generating invoice.

Parameters: 

$display bool whether to proceed displaying regular invoice download link or not
$order object current order object
$location string where download link is displayed ("single" - single order view; "list" - order list view)

 

woo_pdf_allow_proforma_invoice_download

Filter hook called just before displaying proforma invoice download link or download button. Simply return false from your callback function to cancel generating invoice.

Parameters: 

$display bool whether to proceed displaying proforma invoice download link or not
$order object current order object
$location string where download link is displayed ("single" - single order view; "list" - order list view)

 

woo_pdf_prefix_suffix_macros

Filter hook used to add additional macros to be used in invoice number prefix and suffix. Push additional elements to $macros array (macro key as array item key, replacement value as array value) and return it.

Parameters: 

$macros array contains invoice number prefix/suffix macros and their values
$order object current order object
$position string "prefix" or "suffix"

 

woo_pdf_macros

Filter hook used to add additional macros to be used in footer and custom content blocks. Push additional elements to $macros array (macro key as array item key, replacement value as array value) and return it.

Parameters: 

$macros array contains macros and their values
$order object current order object

 

woo_pdf_styles

Filter hook called every time some string changes styles - font size, style and color. You can override any of that and change old values to new (examples below).

Parameters: 

$styles array default array of styles
$order object current order object

Examples:

1 - Changing font size and color:

add_filter('woo_pdf_styles', 'change_invoice_grey_color');
 
function change_invoice_grey_color($styles)
{
    if (isset($styles['color']) && $styles['color'] === '#808080') {
        $styles['color'] = '#000000';
    }
 
    if (isset($styles['size']) && $styles['size'] === 8 ) {
        $styles['size'] = 9;
    }
 
    return $styles;
}
 
2 - Changing font family:
add_filter('woo_pdf_styles', 'change_invoice_font');
 
function change_invoice_font($styles)
{
   $styles['family'] = 'helvetica';
   return $styles;
}
 

woo_pdf_totals

Filter hook called just before displaying the totals block, and can be used to change the data, remove or add any values or just change the order of the totals.

Parameters: 

$totals array default array of totals
$order object current order object
$options array array of options

Example of simple rearranging of the old totals:

add_filter('woo_pdf_totals', 'woo_pdf_change_totals');
 
function woo_pdf_change_totals($totals) {
 
    $new_totals = array(
        'subtotal' => $totals['subtotal'],
        'taxes'    => $totals['taxes'],
        'shipping' => $totals['shipping'],
        'total'    => $totals['total'],
    );
 
    return $new_totals;
}
Have more questions? Submit a request