Back to Community

How to Customize Product Names and Attributes on Your WooCommerce PDF Invoices

Content

Why Customize Your PDF Invoices?

Many WooCommerce store owners need to modify how product information appears on their PDF invoices and packing slips. Common reasons include replacing SEO-optimized product titles with simpler names for accounting, displaying or hiding specific product attributes, or adding a universal prefix like "Digital Product" to all item names. The 'PDF Invoices & Packing Slips for WooCommerce' plugin is designed to display data from your orders, but with a few tweaks, you can tailor this output to meet your specific business needs.

Common Customization Scenarios and Solutions

1. Changing or Adding Text to Product Names

If you need to alter the product name that appears on the invoice, you can use a filter hook in your theme's functions.php file. For example, to add a "Digital Product - " prefix to every product name on the invoice, you can use this code snippet:

/**
 * Add 'Digital Product' before product name on the PDF invoice
 */
add_filter( 'wpo_wcpdf_order_items_data', function( $data_list, $order, $document_type ) {
    if ( $document_type == 'invoice' ) {
        foreach( $data_list as $item_id => $item ) {
            $data_list[$item_id]['name'] = 'Digital Product – ' . $data_list[$item_id]['name'];
        }
    }
    return $data_list;
}, 10, 3 );

Important: Always add custom code to a child theme's functions.php file to prevent it from being overwritten during theme updates.

2. Displaying Product Attributes

The plugin can display product attributes beneath the product name in the item list. The 'PDF Invoices & Packing Slips for WooCommerce' team provides documentation on how to achieve this. Typically, this involves using a code snippet with the wpo_wcpdf_after_item_meta action hook to output the attribute data. The exact code depends on the specific attribute you want to show.

3. Replacing Product Names Based on Category

For more complex replacements, such as showing a generic name like "Physiotherapy consultation" instead of specific product names based on their category, a custom code solution is required. The plugin itself does not manipulate product data; it only displays it. Therefore, you would need to write a custom function that checks the product's category or tags and then changes the name accordingly on the PDF document using available filters. This often requires developer assistance.

Troubleshooting: Why Isn't My Data Showing?

If you've added a code snippet to display custom data but it's not appearing on your PDF, here are a few things to check:

  • Custom PDF Template: If you are using a custom PDF template (e.g., in your child theme), ensure your code is compatible with it. Test first with the default "Simple" template to rule out template-specific issues.
  • Data Timing: Product meta data or attributes must be added to the product before the order is placed. Data added after the order is created is not automatically pulled into existing orders.
  • Cache: Clear any caching on your site after adding new code.

Conclusion

Customizing the product information on your WooCommerce PDF documents is a powerful way to tailor invoices to your business requirements. While simple text changes can be achieved with snippets, more complex conditional logic based on product categories or other factors typically requires custom development. For extensive layout changes, such as adding new columns for attributes, the Premium Templates extension offers a visual customizer tool. Always test code snippets in a staging environment before applying them to your live site.

Related Support Threads Support