We often receive questions about the sequential character of PDF invoice numbers from our WooCommerce PDF Invoices plugin:
- Why is the PDF invoice number different from the WooCommerce order number?
- When is the PDF invoice number assigned?
- How do I reset the invoice numbers?
This article explains exactly how invoice numbers work, and why.
Why do I need sequential invoice numbers?
The answer is simple: because many countries require invoice numbers to be sequential (gaps are not allowed). WooCommerce or WordPress don’t automatically do this for you.
Why is the PDF invoice number different from the WooCommerce order number?
By default, WooCommerce orders are numbered in the main WordPress post numbering system. This includes everything on WordPress: posts, pages, images, orders, coupons, products, etc. So if you create a new product between when two orders are placed, and upload an image for that product too, the order number is not sequential (if the first order was #100, the product would be #101, the image #102 and the next order #103). This is not ideal for invoices, most tax authorities require that invoice numbers are sequential without gaps.
There’s a plugin that fixes this behavior: WooCommerce Sequental Order Numbers. This will make sure that in the above example, the order sequence would not be broken. However, for invoice numbers, this is still not accurate enough. What about fake orders, or orders that are never finished because there was an issue with the payment and the customer places a new order? They get order numbers too, but shouldn’t get an invoice number. This is where a separate invoice numbering system comes in! Which leads us to the next question:
When is the PDF invoice number assigned?
Invoice numbers are assigned at the moment a PDF invoice is created, either manually (by pressing the buttons or executing the bulk action), or automatically (by means of email attachment). This depends completely on the plugin settings. If you attach the invoice to the Admin New Order email, this means the invoice (and invoice number!) will be created immediately after the order is placed – for most setups, this is not recommended! The ‘safest’ way is to attach the PDF invoice only to the Customer Completed Order email and the Customer Invoice email. This will make sure an invoice number will not be created automatically before the order is completed. Additionally, if you want to prevent invoices of ever being created for specific order statuses, you can add these to the “disable for:” setting.
If you want to send the customer an invoice without affecting the invoice numbers, you can use the WooCommerce PDF Invoices & Packing Slips Professional extension: this will allow you to create Proforma Invoices, which have their own, separate (sequential) numbering system.
What about refunded orders?
We can’t change invoice numbers from invoices that have already been issued (in most countries that would be considered a fraudulent action), but with the WooCommerce PDF Invoices & Packing Slips Professional extension you can create Credit Notes. These are negative invoices that can either have a number that is in the same sequence as the invoice numbers, or a completely separate (again, sequential) numbering system.
How do I reset the invoice numbering?
You can reset the invoice numbering in the plugin settings, under Template “Next invoice number”. Enter the number that you want to use for the first invoice that will be created here. Note that this will not change or remove any existing invoice numbers!
But I want the invoice to have the same number as the order!
If you don’t need the invoice numbers to be sequential, and you want the invoice numbers to match the order numbers, you can do so by going to WooCommerce > PDF Invoices > Documents > Invoice and setting the ‘Display invoice number’ option to ‘Order number’.
This will automatically format the order number with all the settings you have configured for the invoice number.
How does the plugin determine the next invoice number?
Internally, the invoice number is created like this:
- Whenever an invoice is requested (could be automatic email attachment or manual creation via the backend), the plugin checks if an the order already has an invoice number (stored as order meta data under ‘_wcpdf_invoice_number’)
- When no invoice number is present in the order, it
- fetches the ‘next invoice number’ from the database (as defined in your plugin settings)
- Assigns that number to the order
- Adds 1 to the ‘next invoice number’ and save to the database.
- When an invoice number is present in the order, it uses that without going through the ‘next invoice number’ loop.