• Resolved salaheddinekhadim

    (@salaheddinekhadim)


    Hello,

    Thanks team for this plugin !
    I succeeded to Filter by Payment Method in My invoice content by :

    $payment_method = $order->get_payment_method();
    if ($payment_method === 'cod') { do....

    I want do the same for Title & Filename of PDF
    by the filter “wpo_wcpdf_invoice_title” and “wpo_wcpdf_invoice_title” but Not working

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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!

    Thread Starter salaheddinekhadim

    (@salaheddinekhadim)

    That’s working for me
    Both codes

    Thanks !

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PDF Title & Filename by Payment Method’ is closed to new replies.