Hooks and Filters in WooCommerce PDF Invoice

The WooCommerce PDF Invoice Extension is fully localized but, occasionally, you might want to change one or two of the output strings so here is a list of available filters and examples :

Template filters ↑ Back to top

apply_filters( 'pdf_template_invoice_number_text', __( 'Invoice No. :', PDFLANGUAGE ) )
apply_filters( 'pdf_template_order_number_text', __( 'Order No. :', PDFLANGUAGE ) )
apply_filters( 'pdf_template_invoice_date_text', __( 'Invoice Date :', PDFLANGUAGE ) )
apply_filters( 'pdf_template_order_date_text', __( 'Order Date :', PDFLANGUAGE ) )
apply_filters( 'pdf_template_billing_details_text', __( '<h3>Billing Details</h3>', PDFLANGUAGE ) ) 
apply_filters( 'pdf_template_shipping_details_text', __( '<h3>Shipping Details</h3>', PDFLANGUAGE ) ) 
apply_filters( 'pdf_template_registered_name_text', __( 'Registered Name : ', PDFLANGUAGE ) ) 
apply_filters( 'pdf_template_registered_office_text', __( 'Registered Office : ', PDFLANGUAGE ) ) 
apply_filters( 'pdf_template_company_number_text', __( 'Company Number : ', PDFLANGUAGE ) ) 
apply_filters( 'pdf_template_vat_number_text', __( 'VAT Number : ', PDFLANGUAGE ) )

Example :

If you wanted to change ‘Vat Number : ‘ to ‘BTW No. : ‘ you would add the following to your theme functions.php file

add_filter( 'pdf_template_vat_number_text', 'custom_pdf_template_vat_number_text' );
function custom_pdf_template_vat_number_text() {
    return 'BTW No. : ';

Change ‘My Orders’ button label ↑ Back to top

 * Change the button label for the PDF Button on the My Orders page
 * This will change the default label (PDF Invoice) to New PDF Label
add_filter ( 'woocommerce_pdf_my_account_button_label' , 'custom_pdf_my_account_button_label' );
function custom_pdf_my_account_button_label() {
    return 'New PDF Label';

Other available actions and filters to make minor changes :

Add additional column to the PDF order items ↑ Back to top

For example you can add the product SKU to the headings and order lines

Or you can change the tax value to tax rate

Adding additional fields to the admin and output PDF ↑ Back to top

To add a new field to the bottom of the settings form you can make use of the action (it is not possible to insert a new field anywhere else at this time)

This code will add a new text field called custom_text to the settings form

add_action ( 'woocommerce_pdf_invoice_additional_fields_admin' , 'custom_woocommerce_pdf_admin_field' );
function custom_woocommerce_pdf_admin_field() {

    $woocommerce_pdf_invoice_options = get_option('woocommerce_pdf_invoice_settings');

            <!-- Custom PDF Field -->
            <tr valign="top">
                <th scope="row" class="titledesc">
                    <label for="woocommerce_pdf_invoice_settings[custom_text]">Custom text for invoice</label>
                    <img class="help_tip" data-tip="Add some custom text to your invoice" src="<?php echo plugins_url( 'woocommerce/assets/images/help.png' );?>" height="16" width="16" />                 
                <td class="forminp forminp-number">
                    <input id="woocommerce_pdf_invoice_settings[custom_text]" 
                    value="<?php if ( isset($woocommerce_pdf_invoice_options['custom_text']) ) { echo $woocommerce_pdf_invoice_options['custom_text']; }?>"
                    placeholder="" style="width: 350px;"/>                     


Once this code is added to your theme functions.php you will see Screen Shot 2013-04-02 at 08.24.57

To add this field to the PDF file you need to add a placeholder – [[CUSTOMFIELD]] – to the template file. Once you have the placeholder added you will need to hook in to the output function.

add_action ( 'pdf_content_additional_content' , 'custom_pdf_additional_content' );
function custom_pdf_additional_content( $content ) {
    global $woocommerce;
    $woocommerce_pdf_invoice_options = get_option( 'woocommerce_pdf_invoice_settings' );

    $content = str_replace( '[[CUSTOMFIELD]]', $woocommerce_pdf_invoice_options['custom_text'], $content );

    return $content;

Examples of adding additional content to the invoice ↑ Back to top

In all cases you need to edit template.php and add your tag in the desired place then add the code to your theme functions.php

Example template.php file used for the adding terms and conditions area example ↑ Back to top

This file should be copied and saved to ‘wp-content/themes/YOUR_THEME/pdf_templates/template.php’

Adding terms and conditions area to the invoice ↑ Back to top

Add Bank Details to footer from WooCommerce BACS settings ↑ Back to top

Add Bank Details under notes section from WooCommerce BACS settings ↑ Back to top

Add a custom field from the order ↑ Back to top

If you are adding custom fields to your checkout, for example Mobile Number, you might want to include this in the invoice. You will need a template tag in the template (see above for examples on how to add template tags), for example [[PDFBILLINGMOBILE]]. Once you have your edited template in place you will need a custom function to replace the template tag when the invoice is generated.

Add billing and or shipping title to the address area ↑ Back to top

This code assumes that you have already included the necessary field on the checkout and have stored it in the order, you can use the WooCommerce Checkout Field Editor plugin for that. The title field should be called billing_title or shipping_title.

Modifying the invoice table headers and content ↑ Back to top

Changes In Version 1.3.0 ↑ Back to top

In previous versions of PDF Invoice each section of the totals area at the bottom of the invoice was handled separately. In version 1.3.0 the totals are handled in one section of code, it can still be filtered if necessary. If you are using the old filters and have not copied the template file to your theme then your filters will no longer work. If you have copied the template to your theme folder then your modifications will remain

This is the new function for outputting the totals section

Reorder the invoice totals section ↑ Back to top

Using the [[PDFORDERTOTALS]] Tag ↑ Back to top

This is the default template tag and the function below will let you re-order the totals section without modifying the template

Using the individual template tags ↑ Back to top

You can edit the template file and replace [[PDFORDERTOTALS]] with the individual tags


And use them in any order you like. If you need to edit the output of any section there are filters available

Full List Of Available Filters ↑ Back to top

Feedback and feature requests ↑ Back to top

For feedback on the PDF Invoice extension, this documentation or for feature requests please email support@chromeorange.co.uk

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top