How to Customize Your WooCommerce PDF Invoice and Packing Slip Templates
Content
Customizing the appearance of your PDF invoices and packing slips is a common need for WooCommerce store owners. Whether you want to change colors, add a logo, or modify the layout, the 'PDF Invoices & Packing Slips for WooCommerce' plugin offers several methods to achieve this. This guide will walk you through the most effective ways to tailor your documents to match your brand.
Why Customize Your PDF Documents?
The default templates provided by the plugin are functional, but they may not align with your company's branding. Customizing these documents can provide a more professional experience for your customers and ensure all necessary information is displayed clearly. Common customizations include adding a paid stamp, changing colors, hiding elements on specific document types, and adjusting margins.
Method 1: Using Custom CSS (Quick Styling Changes)
For simple styling changes, such as modifying colors or hiding certain elements, you can use custom CSS. The plugin provides a hook called wpo_wcpdf_custom_styles for this purpose.
Example: Change Invoice Colors and Hide Packing Slip Header
/**
* Add custom styles to PDF documents
*/
add_action( 'wpo_wcpdf_custom_styles', function( $document_type, $document ) {
if ( $document_type == 'invoice' ) {
?>
/* Change invoice title color and table row background */
.invoice .document-title {
color: #F4EDED;
}
.invoice table.order-details .order-item {
background-color: #F4EDED;
}
/* Hide the header on packing slips */
.packing-slip table.head.container {
visibility: hidden;
}
<?php
}
}, 10, 2 );
This code snippet can be added to your child theme's functions.php file. Remember to adjust the CSS selectors and color codes (#F4EDED) to match your desired design.
Method 2: Creating a Custom Template (Advanced Layout Changes)
For more significant changes to the layout and structure of the PDF, creating a custom template is the recommended approach. This involves copying the plugin's template files to your theme.
Steps to Create a Custom Template:
- Navigate to your theme's directory:
wp-content/themes/your-theme/. - Create a new folder structure:
woocommerce/pdf/yourtemplate/. - Copy the template files from the plugin's
templates/Simpledirectory into your newyourtemplatefolder. The essential files are:invoice.phppacking-slip.phpstyle.css
- Go to WooCommerce > PDF Invoices > General and select your new template from the "Choose a template" dropdown.
- You can now safely edit the PHP and CSS files in your
yourtemplatedirectory. These changes will not be overwritten by plugin updates.
Important Note: Never edit the plugin's core template files directly. They will be completely overwritten and lost during the next update. Always use a custom template in your theme.
Method 3: Using Code Snippets for Functional Changes
Some changes require using filters provided by the plugin. For instance, to change the title of the invoice document or the filename.
Example: Change "Invoice" Title to "Order Confirmation"
/**
* Customize the invoice title
*/
add_filter( 'wpo_wcpdf_invoice_title', function( $title, $document ) {
$title = 'Order Confirmation';
return $title;
}, 10, 2 );
Example: Capitalize the First Letter in the Filename
/**
* Customize the invoice filename
*/
add_filter( 'wpo_wcpdf_filename', function( $filename, $document_type, $order_ids ) {
if ( $document_type == 'invoice' ) {
$filename = 'Invoice-' . $order_ids . '.pdf';
}
return $filename;
}, 10, 3 );
Troubleshooting Common Issues
- Custom template not showing: Double-check the folder path. It must be
wp-content/themes/yourtheme/woocommerce/pdf/yourtemplate/. Also, ensure you have selected the custom template in the plugin's settings. - CSS changes not working: Use the
wpo_wcpdf_custom_styleshook for CSS that is specific to a document type (e.g., invoice or packing slip). For general CSS, you can add it to thestyle.cssfile within your custom template folder. - Need a page break: This can be achieved with CSS. Inside your custom styles, you can use
page-break-before: always;on an element to force a new page.
By following these methods, you can effectively customize your WooCommerce PDF documents to meet your specific business needs. For more complex layout changes that require a drag-and-drop interface, the 'PDF Invoices & Packing Slips for WooCommerce' team offers a Premium Templates extension with a built-in customizer.
Related Support Threads Support
-
Customize invoicehttps://wordpress.org/support/topic/customize-invoice-2/
-
Create a cover page/ PDF margingshttps://wordpress.org/support/topic/create-a-cover-page-pdf-margings/
-
Other document creation guidelines for paid and free versionshttps://wordpress.org/support/topic/other-document-creation-guidelines-for-paid-and-free-versions/
-
Buld delete invoiceshttps://wordpress.org/support/topic/buld-delete-invoices/
-
How to edit old invoiceshttps://wordpress.org/support/topic/how-to-edit-old-invoices/
-
Customer template deleted after updatehttps://wordpress.org/support/topic/customer-template-deleted-after-update/
-
How to change the colours of the invoice template?https://wordpress.org/support/topic/how-to-change-the-colours-of-the-invoice-template/
-
Need paid title or Logo for pdf invoiceshttps://wordpress.org/support/topic/need-paid-title-or-logo-for-pdf-invoices/
-
Different templateshttps://wordpress.org/support/topic/different-templates-4/
-
custom template code not updatedhttps://wordpress.org/support/topic/custom-template-code-not-updated/
-
child theme invoice.phphttps://wordpress.org/support/topic/child-theme-invoice-php/
-
Need a link without blank?https://wordpress.org/support/topic/need-a-link-without-blank-2/
-
Pre-Sale Question for Pro versionhttps://wordpress.org/support/topic/pre-sale-question-for-pro-version/
-
Change template without child themehttps://wordpress.org/support/topic/change-template-without-child-theme/
-
Editing Templates Could Be Easierhttps://wordpress.org/support/topic/editing-templates-could-be-easier/
-
Personnaliser design facturehttps://wordpress.org/support/topic/personnaliser-design-facture/
-
Design Invoicehttps://wordpress.org/support/topic/design-invoice/
-
Different CSS style depending on document typehttps://wordpress.org/support/topic/different-css-style-depending-on-document-type/
-
Issue with premium templatehttps://wordpress.org/support/topic/issue-with-premium-template/
-
How to edit templatehttps://wordpress.org/support/topic/how-to-edit-template-2/
-
Thermal printer paper size & Remove Variation priceshttps://wordpress.org/support/topic/thermal-printer-paper-size-remove-variation-prices/
-
Starting the invoice filename with a capitalhttps://wordpress.org/support/topic/starting-the-invoice-filename-with-a-capital/