Hi @ujjwalr10
you can add cod to template-functions.php
add_filter( ‘wpo_wcpdf_filename’, ‘wpo_wcpdf_custom_filename’, 10, 4 );
function wpo_wcpdf_custom_filename( $filename, $template_type, $order_ids, $context ) {
$count = count($order_ids);
if ( $count == 1 && $template_type == ‘invoice’) {
$order = wc_get_order($order_ids[0]);
$Customer_name = $order->get_billing_first_name() . ‘ ‘ . $order->get_billing_last_name();
$invoice_string = _n( ‘invoice’, ‘invoices’, count( $order_ids ), ‘woocommerce-pdf-invoices-packing-slips’ );
# change the filename
$filename = $Customer_name. ‘-‘ . $invoice_string. ‘-‘ . $order->get_order_number() .’.pdf’;
}
return $filename;
}
Plugin Contributor
Ewout
(@pomegranate)
@homdr that snippet changes the filename (adding the order number and customer name), but they want to change the title of the document adding the invoice number.
In the Professional extension you can do this via the settings, adding the {{document_number}} placeholder:

If you prefer a filter for the free plugin you can use:
add_filter( 'wpo_wcpdf_invoice_title', 'wpo_wcpdf_invoice_title', 10, 2 );
function wpo_wcpdf_invoice_title ( $title, $document ) {
if ($document && $document->exists()) {
$invoice_number = !empty($document->get_number()) ? $document->get_number()->get_formatted() : '';
$title = sprintf( "Tax Invoice #%s", $invoice_number );
} else {
$title = 'Tax Invoice';
}
return $title;
}
Thread Starter
Ujjwal
(@ujjwalr10)
@pomegranate
This code changes the title of the document, but not the way I want it.
I want the customer name in the document title with the document number.
see this image –
https://drive.google.com/file/d/1nyLjcRAgJPtlqmIN4IL3Iqfp-h-nUf72/view?usp=sharing
problem is that we download all files in local storage, and at that time we change the document title with the customer name.
if we don’t do that then it makes us confuse to know which bill is number is related to which customers.
opening every bill for knowing customer name is not a good idea.
So that, if the name of the customer is in the invoice title, it can help a lot.
Please also tell me how can I share the link of the invoice with the customers.
Thread Starter
Ujjwal
(@ujjwalr10)
Thread Starter
Ujjwal
(@ujjwalr10)
@homdr after resolving error all fine
but file name not changing.
-
This reply was modified 5 years ago by
Ujjwal.
-
This reply was modified 5 years ago by
Ujjwal.
Hello @ujjwalr10,
Try using this code snippet:
add_filter( 'wpo_wcpdf_invoice_title', 'wpo_wcpdf_invoice_title', 10, 2 );
function wpo_wcpdf_invoice_title ( $title, $document ) {
if ($document && $document->exists()) {
$customer_name = $document->order->get_billing_first_name() . ' ' . $document->order->get_billing_last_name();
$invoice_number = !empty($document->get_number()) ? $document->get_number()->get_formatted() : '';
$title = sprintf( '%1$s - Invoice #%2$s', $customer_name, $invoice_number );
} else {
$title = 'Invoice';
}
return $title;
}
Please, let me know if works 🙂
Thread Starter
Ujjwal
(@ujjwalr10)
I have the same error, any solution?
Plugin Contributor
Ewout
(@pomegranate)
That’s the filename, this forum topic is about the document title. To change the filename, please refer to this documentation:
Custom PDF filenames