Plugin Contributor
Ewout
(@pomegranate)
Hi! There’s a snippet on how to add a prefix to the filename in the FAQ.
Additionally, to replace the word invoice with something else, try this:
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);
// prepend your shopname to the file
$new_filename = 'myshopname_' . $filename;
$new_filename = str_replace( _n( 'invoice', 'invoices', $count, 'wpo_wcpdf' ), _n( 'booking', 'bookings', $count, 'wpo_wcpdf' ), $new_filename);
return $new_filename;
}
Hello , thank’s..this resolve in part.
I’ve put the code on my function.php and the result on file name is:
myname_invoice-31B2015.pdf ..so i like also to delete or change the invoice name on file.
I use this:
add_filter('woocommerce_thankyou_order_received_text', 'wpo_wcpdf_thank_you_link', 10, 2);
function wpo_wcpdf_thank_you_link( $text, $order ) {
if ( is_user_logged_in() ) {
$pdf_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=invoice&order_ids=' . $order->id . '&my-account'), 'generate_wpo_wcpdf' );
$text .= '<p><a href="'.esc_attr($pdf_url).'">Scarica la ricevuta della tua donaziona in PDF</a></p>';
}
return $text;
}
Plugin Contributor
Ewout
(@pomegranate)
Hi!
You have posted another filter, can you post the one for the filename? The one I posted works, but note that it has two translations for both the single and plural (‘booking’ and ‘bookings’ in the example).
Ewout
Hello,
sorry…this function:
// Cambia Nome Fattura
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);
// prepend your shopname to the file
$new_filename = 'ricevuta_' . $filename;
$new_filename = str_replace( _n( 'ricevuta', 'ricevuta', $count, 'wpo_wcpdf' ), _n( 'ricevuta', 'ricevuta', $count, 'wpo_wcpdf' ), $new_filename);
return $new_filename;
}
Plugin Contributor
Ewout
(@pomegranate)
You’re trying to replace ricevuta with ricevuta, you should only change the second part so it knows what to look for (the first part) 😉
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);
// prepend your shopname to the file
$new_filename = 'ricevuta_' . $filename;
$new_filename = str_replace( _n( 'invoice', 'invoices', $count, 'wpo_wcpdf' ), _n( 'ricevuta', 'ricevuta', $count, 'wpo_wcpdf' ), $new_filename);
return $new_filename;
}