Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Create Random Custom Order Numbers in WooCommerce?

By default, WooCommerce provides non-sequential order numbers based on the WordPress core post IDs. We will take a step further to make these default order numbers more unique and distinguishable by creating custom random order numbers. This WooCommerce customization is especially used in cases where store owners prefer random order numbers over sequential ones for enhanced security or privacy. Let’s dive in to know how to implement this!

Solution: Create Random Custom Order Numbers in WooCommerce

The code snippet generates random order numbers and this random number is then concatenated with the string 'ORD-' to form the final order number.

add_filter( 'woocommerce_order_number', 'ts_custom_order_number', 1, 2 );
function ts_custom_order_number( $order_id, $order ) {
    return 'ORD-' . rand( 1000, 9999 ); // Random order number
}

Output

With the php rand function, the code generates the random number prefixed with the string ‘ORD-‘. For example, if the original order ID is #1800, the code will replace the original order id with the unique order id as ‘#ORD-2890’.

How to Create Random Custom Order Numbers in WooCommerce? - Tyche Softwares

What if you prefer to display the typical sequential order numbers instead of random ones? Don’t worry, we have got your back on this one also. You can easily add sequential custom order numbers in WooCommerce using the step-by-step guide and make sure the orders are organized in sequence.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x