Back to Community

How to Add Custom Fields and Data to Your WooCommerce PDF Invoices

Content

Why Customize Your PDF Invoices?

Many WooCommerce store owners need to display specific information on their invoices, such as VAT numbers, custom checkout fields, or special payment instructions. The free 'PDF Invoices & Packing Slips for WooCommerce' plugin is highly extensible and allows for this kind of customization through code snippets and template edits.

Finding the Right Approach

Based on common community questions, there are two primary methods for adding custom data to your PDF documents:

1. Displaying Custom Field Data

If you have collected custom data during checkout (e.g., a VAT number or a special request field) and want to display it on the invoice, you will need two things:

  • The Meta Key: This is the unique identifier for your custom field's data, stored in the order's metadata.
  • A Code Snippet: A small piece of PHP code that tells the plugin to fetch and display that data.

The 'PDF Invoices & Packing Slips for WooCommerce' team provides a comprehensive guide on their documentation site for displaying custom fields. You will need to use the correct meta key for your field within the provided code example.

2. Adding Static Information

To add static text, like fixed bank details or terms and conditions, you can use a WordPress action hook. A common solution is to use the wpo_wcpdf_after_order_details hook to insert your content after the order table. For example:

add_action( 'wpo_wcpdf_after_order_details', function( $document_type, $order ) {
    if ( $document_type == 'invoice' ) {
        ?>
        <div class="custom-bank-details">
            <h3>Bank Transfer Instructions</h3>
            <p>Account Name: Your Name<br>
            BSB: 000-000<br>
            Account Number: 123456789</p>
        </div>
        <?php
    }
}, 10, 2 );

This code can be added to your child theme's functions.php file or managed using a plugin like 'Code Snippets'.

Important Considerations and Troubleshooting

  • Conditional Logic: You can make information appear based on certain conditions, like the payment method used. The wpo_wcpdf_document_is_allowed filter can be used to control whether a document is created at all based on custom logic, such as the presence of a company name.
  • Template Overrides: For more advanced layout changes, you can copy the plugin's template files (e.g., invoice.php) to a wpo_wcpdf folder within your child theme. This lets you modify the HTML structure directly.
  • Finding Meta Keys: If you are unsure what the meta key is for your custom field, you may need to use a helper plugin or inspect your site's database to find the correct value.

By understanding these core methods, you can significantly extend the functionality of your PDF invoices to meet your specific business needs.

Related Support Threads Support