Plugin Contributor
Ewout
(@pomegranate)
Hello Michael,
The internal PDF invoice number is made for one single purpose, which is that it always to be sequential (i.e. leaving no gaps in the numbers). This is EU law.
The only way to reliably accomplish this is to generate the number upon creation of the invoice (PDF). If the invoice number would be linked to either the order in which the orders are placed (remember, not all orders will be finished in most webshops), or the woocommerce order number, this would always leave gaps. For this reason, the PDF invoice number operates completely separate from the WooCommerce order number.
However, if you do not have to abide to this EU law, you can choose the option “WooCommerce Order Number” in the PDF invoice settings panel, and the invoice will have the order number instead of the sequential invoice number. Any ‘link’ between the two numbers is not possible without breaking the sequential character of the system.
There’s another option, if you have two invoice systems, you can control the ‘next invoice’ number from the settings panel. This way you can skip several invoice numbers when they have already been generated with the other system.
So the invoice number is not ‘wrong’, and if you want to use the woocommerce order number that’s an option in the settings panel.
Thanks for clarification :).
Invoices from your program don’t meet invoice requirements from my country (Poland) so I use them merely as a printed sum up of an order, so the setting “woocommerce order number” will be perfect then!
Once again, thanks for the full info :).
I can’t find the “WooCommerce Order Number” setting. Where is it?
I am looking in WooCommerce > PDF Invoices and in the three tabs.
Weird. I could have sworn I saw this in woocommerce settings or near by but now when you mentioned it, I can’t find it either. Maybe they changed it in newer versions?
Is it possible you just need to leave the “next invoice number” box blank and it will not just sync the number automatically?
Plugin Contributor
Ewout
(@pomegranate)
Hello Steve,
There’s several approaches to solving this.
1a) The simplest solution is indeed to leave the “Display built-in sequential invoice number” unchecked. It will then not print any invoice number in the PDF at all and just show the order number.
1b) If you want it to say “Invoice Number” instead of “Order Number”, you’ll have to edit/customize the template (following instructions from the template settings page) and simply rename the label.
2) If you want it display the same number twice, once as “Order Number” and once as Invoice number (formatted according to the settings), you can add the following code to your theme’s functions.php:
/**
* 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, '#');
// get format settings
$template_settings = get_option('wpo_wcpdf_template_settings');
$formats['prefix'] = isset($template_settings['invoice_number_formatting_prefix'])?$template_settings['invoice_number_formatting_prefix']:'';
$formats['suffix'] = isset($template_settings['invoice_number_formatting_suffix'])?$template_settings['invoice_number_formatting_suffix']:'';
$formats['padding'] = isset($template_settings['invoice_number_formatting_padding'])?$template_settings['invoice_number_formatting_padding']:'';
// Replacements
$order_year = date_i18n( 'Y', strtotime( $order_date ) );
$order_month = date_i18n( 'm', strtotime( $order_date ) );
foreach ($formats as $key => $value) {
$value = str_replace('[order_year]', $order_year, $value);
$value = str_replace('[order_month]', $order_month, $value);
$formats[$key] = $value;
}
// Padding - minimum of 3 for safety
if ( ctype_digit( (string)$formats['padding'] ) && $formats['padding'] > 3 ) {
$invoice_number = sprintf('%0'.$formats['padding'].'d', $invoice_number);
}
$formatted_invoice_number = $formats['prefix'] . $invoice_number . $formats['suffix'] ;
return $formatted_invoice_number;
}
Good luck!
Ewout
I think you may have misunderstood.
My order numbers and invoice numbers are out of sync.
For example, order #1176 has an invoice number #1104
Why can’t the invoice number be the same as the order number in all cases? See this screenshot: https://docs.google.com/file/d/0B_ynoyoLwXgTNjFUckNFM1I1Ykk/edit?usp=drivesdk
Why is the invoice number different to the order number? This is just confusing.
Plugin Contributor
Ewout
(@pomegranate)
This is because in many countries (all of the EU for example!) invoice numbers cannot have gaps in them – the need to be numbered sequentially. There’s a plugin to have the order numbers numbered sequentially, WooCommerce Sequential Order Numbers. However, this is often not enough, because cancelled and failed orders still get an order number. Enter separate invoice numbers. Invoice numbers are only created when an invoice is created, and always sequential. This is extremely important for European shops.
That said, option 2) will display the same number in both columns.
Ewout
Great, thank-you. Perhaps this piece of code could be added to the FAQs section?