Viewing 1 replies (of 1 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hello Abhi,
    You have to do this with the wpo_wcpdf_invoice_number filter. There is an example in the docs: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/invoice-numbers-explained/#but-i-want-the-invoice-to-have-the-same-number-as-the-order

    This particular example uses the formatting from the settings, but you can also use it without reusing those settings:

    /**
     * Format order number with invoice number settings
     */
    add_filter( 'wpo_wcpdf_invoice_number', 'wpo_wcpdf_format_invoice_number', 20, 4 );
    function wpo_wcpdf_format_invoice_number( $invoice_number, $order_number, $order_id, $order_date ) {
        // We want to use the order number as invoice number!
        $invoice_number = ltrim($order_number, '#');
    
        $order_year = date_i18n( 'Y', strtotime( $order_date ) );
        $order_month = date_i18n( 'm', strtotime( $order_date ) );
        $order_day = date_i18n( 'd', strtotime( $order_date ) );
    
        $formatted_invoice_number = "XX-{invoice_number}-{$order_year}{$order_month}{$order_day}";
    
        return $formatted_invoice_number;
    }

    Note that using the order number as invoice number will likely break the sequential character of the invoice numbers when you get cancelled or unfinished orders, even if you’re using woocommerce sequential invoice numbers!

    Have a great day!
    Ewout

Viewing 1 replies (of 1 total)
  • The topic ‘How to customize generated invoice number’ is closed to new replies.