Thank you as always. I did wonder if the code button did that, but not being able to preview the post before submitting, I didn’t want to risk it!
I added the code you kindly suggested, and it worked in that the filename then had the user_login appended . . . but the filename now consisted of user_login–user_login – ie the name of the attachment (which was ‘Order acknowledgement’, translated from ‘Invoice’) has been swapped for user_login.
So, in a spirit of adventure, I’ve now taken the liberty of editing your code at various points:
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);
switch ($template_type) {
case 'invoice':
$name = _n( 'invoice', 'invoices', $count, 'woocommerce-pdf-invoices-packing-slips' );
break;
case 'packing-slip':
$name = _n( 'packing-slip', 'packing-slips', $count, 'woocommerce-pdf-invoices-packing-slips' );
break;
case 'proforma':
$name = _n( 'proforma-invoice', 'proforma-invoices', $count, 'wpo_wcpdf_pro' );
break;
case 'credit-note':
$name = _n( 'credit-note', 'credit-notes', $count, 'wpo_wcpdf_pro' );
break;
default:
$name = $template_type;
break;
}
/* if ( $count == 1 ) {
$document = wcpdf_get_document( $template_type, $order_ids );
if ( $number = $document->get_number() ) {
$suffix = $number;
} elseif (isset($document->order) && method_exists($document->order, 'get_order_number')) {
$number = $document->order->get_order_number();
} else {
$number = $order_ids[0];
}
$suffix = $number;
} else
*/
{
$suffix = date('d-m-Y'); // 25-07-2019
}
if ( $count == 1 ) {
$order = wc_get_order($order_ids[0]);
if ( $user = $order->get_user() ) {
$name = $user->user_login;
} else {
$name = $order->get_formatted_billing_full_name();
}
/* $suffix = "{$suffix}-{$name}";
*/
}
$filename = 'Order acknowledegment for ' . $name . '-' . $suffix .'.pdf';
return $filename;
}
The suffix is now the date (formatted for the UK), and I’ve put in ‘Order acknowledgement for’ as plain text.
I apologise if I’ve committed any crimes against coding, but it does seem to work, and I thought I ought to have a go at doing it myself rather than always relying on you!
Now to look into removing those annoying dashes in the text . . .