Yes, I have been in the same situation too. You set up Woocommerce, and add products, and everything looks fine until the orders start coming in. Random Order Numbers!!!! Hang tight there, let’s fix this using a free method.
Table of Contents
1. Introduction: The Problem with Random Order Numbers in WooCommerce
WooCommerce is one of the most popular eCommerce platforms, but by default, the order numbers it generates are not sequential. Instead, WooCommerce uses WordPress’s ID system for posts and pages, resulting in random gaps between order numbers.
For example, after order #1503, your next order might be #1507. This randomization happens because WordPress assigns an ID to every new post type (such, as posts, pages, or orders). This can be problematic for businesses that need sequential numbers for tracking, accounting, or legal purposes.
2. Why You Should Use Sequential Order Numbers
Here are some key reasons why using sequential order numbers can benefit your WooCommerce store:
- Easier Tracking: Sequential order numbers help keep your order management process more organized.
- Accounting and Legal Compliance: Some businesses are required by law to maintain sequential invoice numbers for taxation and legal purposes.
- Professional Appearance: Random gaps in order numbers can confuse customers, especially if they associate gaps with missing orders.
Without a fix, you may encounter operational issues that affect both the backend management and customer-facing side of your store.
3. How to Fix WooCommerce Random Order Numbers
Fortunately, there’s a simple solution to fix this issue: you can implement a custom PHP script that forces WooCommerce to generate sequential order numbers starting from a specific number, like 1000. This makes it much easier for you to track orders efficiently and present a cleaner, more organized system to your customers.
Next, we’ll walk through a custom PHP snippet that you can easily integrate into your WooCommerce store.
4. PHP Script for Sequential WooCommerce Order Numbers Starting from 1000
Below is a PHP script that you can use to ensure your WooCommerce orders are in sequential order, starting from 1000. You can change the number 1000 to any other number if you want.
// Function to set custom sequential order numbers
function custom_sequential_order_numbers($order_id) {
// Define the starting order number
$starting_number = 1000;
// Check if the order has a custom meta for sequential numbering
$order_number = get_post_meta($order_id, '_custom_order_number', true);
// If it doesn't, generate a new sequential order number
if (!$order_number) {
// Get the last order's custom number
$last_order_number = get_option('last_custom_order_number', $starting_number - 1);
// Increment by 1
$new_order_number = $last_order_number + 1;
// Update the order meta with the new sequential number
update_post_meta($order_id, '_custom_order_number', $new_order_number);
// Save the new number as the last order number
update_option('last_custom_order_number', $new_order_number);
}
}
// Hook into WooCommerce's order creation process
add_action('woocommerce_checkout_update_order_meta', 'custom_sequential_order_numbers');
// Function to display the custom order number in the admin and frontend
function display_custom_order_number($order_number, $order) {
// Get the custom order number
$custom_order_number = get_post_meta($order->get_id(), '_custom_order_number', true);
// If it exists, use it as the order number
if ($custom_order_number) {
return $custom_order_number;
}
// Otherwise, return the default WooCommerce order number
return $order_number;
}
// Hook to display the custom order number in both admin and customer-facing areas
add_filter('woocommerce_order_number', 'display_custom_order_number', 10, 2);
This script ensures that each WooCommerce order receives a unique, sequential number that starts from 1000. This is useful if you want your order numbers to appear more professional or if your business has specific regulatory requirements.
5. How to Implement the Script in Your WooCommerce Store
Follow these simple steps to integrate the script into your store:
1. Edit Theme’s functions.php
File
- This is not an effective method, because each time when WordPress Updates, your customization will be replaced with new Codes.
- Go to your WordPress admin panel.
- Navigate to
Appearance
→Theme File Editor
. - Select
functions.php
from the right-hand panel. - Paste the PHP script at the bottom of the file.
2. Best method: using the Code Snippets plugin [ FREE ]
- Recommended method. Install and activate the Code Snippets plugin on your WordPress website. The pro version is not required.
- Add new and Select Functions PHP.
- Copy and paste the above code inside the editor.
- Change numeric value 0001 to your choice. ( $starting_number = 0001; )
- Select ‘Run Everywhere’, and give it a title and description for reference.
- Click Save and activate. You are good to go!
3. Alternatively, Create a Custom Plugin
If you prefer not to modify your theme’s functions.php
file, you can create a custom plugin:
- Create a new folder under
wp-content/plugins/
and name itcustom-sequential-order-numbers
. - Inside this folder, create a PHP file named
custom-sequential-order-numbers.php
and paste the script into it. - Activate the plugin from the WordPress dashboard by going to
Plugins
→Installed Plugins
.
6. Conclusion: Better Organization with Sequential Order Numbers
Having sequential order numbers in your WooCommerce store can streamline your order management, improve customer satisfaction, and help with legal compliance. By implementing the provided PHP snippet, you can fix the default random order number behaviour and ensure that your order numbers start from 1000 and increment consistently. Whether you’re dealing with a small online shop or a large eCommerce business, this simple change can make a big difference.
By applying this method, you’ll have a much cleaner and more reliable order number system that enhances both your internal processes and your customers’ experiences.