Plugin Contributor
Ewout
(@pomegranate)
are you referring to the title, or the filename?
See:
Change the document title
Custom pdf filenames
Ewout thank you so much 🙂
I’m referring to the filename.
For example, So far I get: invoice-128.pdf
but I need to have this:
128 – [Buyers Name] (Price) (Date).pdf
128 – [Jonathan] (204.3€) (Aug).pdf
So how can I retrieve the name of the buyer, number of the invoice, and the price as well?
$new_filename = $numberInvoice.’-[‘.$buyer.’](‘.$price.’)(‘.$date.’).pdf’;
return $new_filename;
I hope you got the point 🙂
Plugin Contributor
Ewout
(@pomegranate)
For the free version you’ll have to collect this information yourself from the order object in the last example on the documentation page: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/custom-pdf-filenames/#free-version
This is quite custom and beyond what we can offer as part of free support.
With the Professional extension you can use placeholders for this in the filename format:
{{document_number}}-{{formatted_billing_full_name}}-{{order_total}}-{{order_date}}.pdf
Hi Ewout,
Unfortunately, I’m trying to just copy-paste the code from your examples on the function.php but the functions don’t find an application. Did I miss something?
It seems that when I download the pdf file the filename remains the same.
Just to let you know, I’m not the beginner WP users.
Plugin Contributor
Ewout
(@pomegranate)
The “example 4” does indeed not change anything, it simply gives you a basis to work from but you’ll need to add the customizations yourself.
I got the point with the example4.
Even if I put some custom text on the $filename still doesn’t take any effect on the file name
Plugin Contributor
Ewout
(@pomegranate)
can you share your code with us here? And can you double check that you are using this PDF invoice plugin (“WooCommerce PDF Invoices & Packing Slips”, version 2.3.3)
Just a simple snippet
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);
$name = _n( 'invoice', 'invoices', $count, 'woocommerce-pdf-invoices-packing-slips' );
$filename = $name . 'Invoice Custom Text.pdf';
return $filename;
}
version 2.3.3 -> https://ibb.co/7Nzdy14
Plugin Contributor
Ewout
(@pomegranate)
That looks fine to me. Some themes/sites disable function.php in certain contexts. Can you try the Code Snippets plugin to rule this out (and don’t forget to rename the function to something else to prevent crashes on duplicate function names:
add_filter( 'wpo_wcpdf_filename', 'wpo_wcpdf_custom_filename_2', 10, 4 );
function wpo_wcpdf_custom_filename_2( $filename, $template_type, $order_ids, $context ) {
$count = count($order_ids);
$name = _n( 'invoice', 'invoices', $count, 'woocommerce-pdf-invoices-packing-slips' );
$filename = $name . 'Invoice Custom Text.pdf';
return $filename;
}
-
This reply was modified 6 years, 7 months ago by
Ewout. Reason: prevent duplicate function names
Really appreciate your effort and your guidance,
I will follow your recommendations.
You won a review 🙂