• Resolved dm007

    (@dm007)


    Hello,

    Could you provide a functions.php example to replace the invoice number with the Woocommerce order number for the Free version?

    I did try and read the Custom PDF Filename page but was not able to accomplish this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi!
    The documentation for creating custom filenames can be found here:
    Custom PDF filenames.

    By far the easiest way to accomplish this is with the Professional extension because it lets you do this via the plugin settings the {{order_number}} placeholder.

    Here’s a filter that uses the order number in the filename:

    
    add_filter( 'wpo_wcpdf_filename', 'wpo_wcpdf_custom_filename',9999, 4 );
    function wpo_wcpdf_custom_filename( $filename, $template_type, $order_ids, $context ) {
        if ($template_type == 'invoice' && count($order_ids) == 1 ) {
            $order_id = array_pop( $order_ids );
            $order = wc_get_order( $order_id );
            $order_number = $order->get_order_number();
            $name = _n( 'invoice', 'invoices', 1, 'woocommerce-pdf-invoices-packing-slips' );
            $filename = "{$name}-{$order_number}.pdf";
        }
        return $filename;
    }
    

    Hope that helps!

    Thread Starter dm007

    (@dm007)

    Thanks so much! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Replace Invoice Number with Order Number in Filename’ is closed to new replies.