Plugin Contributor
Ewout
(@pomegranate)
You can find more information about the filename filter (wpo_wcpdf_filename) here:
https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/custom-pdf-filenames/
Here’s an example:
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]);
if ( $order->get_payment_method() === 'cod' ) {
# change the filename
$filename = $order->get_order_number().'-cod.pdf';
}
}
return $filename;
}
Be careful to always use a unique identified in the filename for each order, otherwise if you get many orders at the same time, they overwrite eachothers files during the email attachment process.
More information about the wpo_wcpdf_invoice_title filter can be found here:
https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/change-the-document-title/#free-version
You can access the order object through the document parameter, but note that the title is also called outside of the order context so you need an extra check:
add_filter( 'wpo_wcpdf_invoice_title', 'wpo_wcpdf_invoice_title', 10, 2 );
function wpo_wcpdf_invoice_title ( $title, $document = null ) {
if (!empty($document) && !empty($document->order)) {
if ( $document->order->get_payment_method() === 'cod' ) {
$title = 'COD Invoice';
}
}
return $title;
}
Hope that helps!
That’s working for me
Both codes
Thanks !