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_allowedfilter 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 awpo_wcpdffolder 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
-
Conditional PDF sending by product categoryhttps://wordpress.org/support/topic/conditional-pdf-sending-by-product-category/
-
Get PDF for external Toolhttps://wordpress.org/support/topic/get-pdf-for-external-tool/
-
loading on frontendhttps://wordpress.org/support/topic/loading-on-frontend/
-
Payment Method Instructions on PDF Invoicehttps://wordpress.org/support/topic/payment-method-instructions-on-pdf-invoice/
-
Custom field in invocie pdfhttps://wordpress.org/support/topic/custom-field-in-invocie-pdf/
-
viewing the PDF in a popuphttps://wordpress.org/support/topic/viewing-the-pdf-in-a-popup/
-
set custom field in invoicehttps://wordpress.org/support/topic/set-custom-field-in-invoice/
-
Add static field for Bank detailshttps://wordpress.org/support/topic/add-static-field-for-bank-details/
-
Upload PDF to Mediahttps://wordpress.org/support/topic/upload-pdf-to-media/
-
Create second PDF with different headerhttps://wordpress.org/support/topic/create-second-pdf-with-different-header/
-
Custom text on PDF invoice based on payment method?https://wordpress.org/support/topic/custom-text-on-pdf-invoice-based-on-payment-method/
-
Salesforce integrationhttps://wordpress.org/support/topic/salesforce-integration-11/
-
Add a pdf file (cgv) after the invoice generatedhttps://wordpress.org/support/topic/add-a-pdf-file-cgv-after-the-invoice-generated/
-
Embed UBL in PDFhttps://wordpress.org/support/topic/embed-ubl-in-pdf/
-
Cloud storage in One Drivehttps://wordpress.org/support/topic/cloud-storage-in-one-drive/
-
New Documenthttps://wordpress.org/support/topic/new-document/
-
Custom fieldshttps://wordpress.org/support/topic/custom-fields-432/
-
Upload PDF Invoiceshttps://wordpress.org/support/topic/upload-pdf-invoices/
-
Direct link to the generated PDFhttps://wordpress.org/support/topic/direct-link-to-the-generated-pdf/
-
Add Third-Party Delivery Fee to PDF Invoice Using Hooks or Filters?https://wordpress.org/support/topic/21-delivery-fee-tax-integration-on-thank-you-page-and-pdf-invoice-plugin-hooks/
-
Insert in the PDF one custom fieldhttps://wordpress.org/support/topic/insert-in-the-pdf-one-custom-field/
-
Is there a way to automate PDF generation?https://wordpress.org/support/topic/is-there-a-way-to-automate-pdf-generation/
-
Modifying the filename when saving a PDFhttps://wordpress.org/support/topic/modifying-the-filename-when-saving-a-pdf/
-
Choose when the PDF is attachedhttps://wordpress.org/support/topic/choose-when-the-pdf-is-attached/
-
Custom field/pdf per producthttps://wordpress.org/support/topic/custom-field-pdf-per-product/
-
Digital SIgnaturehttps://wordpress.org/support/topic/digital-signature-5/
-
ACF data in productshttps://wordpress.org/support/topic/acf-data-in-products/