Patrick's Programming Blog

Why WooCommerce Order Numbers Are out of Order

Out of Order WooCommerce Order Numbers

22, 23, 25, 39, 40 – What!? Why are my order numbers out of order? If you've used WordPress before you might know that posts, pages, and media files have IDs that aren't necessarily in order. The first one might be 20 and the next might be 43. WooCommerce uses the same ID system to create the order number which is why they're out of order.

For your average marketing website this isn't a big deal since you rarely need that number. In the e-commerce world with accounting software, drop shippers, & reports it makes a lot more sense to have consecutive order numbers. The good news is that this is really easy to do with a plugin.

Why The Order Numbers Are out of Order

First it's important to know why all of these IDs are out of order in the first place. WordPress saves everything as a post. So pages are posts, media files are posts, products are posts, orders are posts, and posts are posts. This makes it really easy for developers to interact with the database since everything uses a similar format. All of these posts (media, pages, posts, etc) use the same database table and because of that they can't share the same ID. If you want to have a consecutive order number then you have to save a bit of extra data in the database.

The design pattern behind WooCommerce is to try to stay as lean as possible and give people the ability to extend or add onto the existing functionality. If you don't need sequential order numbers then there's no point in storing all of this extra information. WooCommerce leaves this up to store manager to decide if it's necessary.

How to Make the Order Numbers Sequential

Any plugin developer can add a bit of extra data to the orders to make sure they're in order. In fact there's already an excellent plugin, WooCommerce Sequential Order Numbers, by the SkyVerge team available for free on WordPress.org. They even have a premium version with a few extra features like the ability to add a prefix ex. MyStore so your order numbers would look like MyStore001, MyStore002, etc.

Happy sequential order numbers!

More Commonly Asked WooCommerce Questions in My Book

If you want to learn more about the commonly asked WooCommerce questions I suggest you take a look at my book. It isn't out yet but you can signup for the mailing list and get a discount when it comes out.

Exit mobile version