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

How to Set the Width of  Custom Order Number In WooCommerce?

By setting specific prefixes or suffixes you can adjust the width of your order numbers. There are plugins out there to help you with this, but for the folks who want even more flexibility and control, you can choose the WooCommerce customization route.

In this guide, we’ll walk you through setting your order numbers to a 10-digit format. Ready to give your store a personalized touch? Let’s dive in!

Solution: Set the Width of  Custom Order Number In WooCommerce

The code snippet modifies the default order ID with a CRC32 hash which is a pseudorandom number derived from the order ID and sets the width of it to a unique 10-digit number.

add_filter( 'woocommerce_order_number', 'add_order_hash_to_order_number', 1, 2 );

function add_order_hash_to_order_number( $order_id, $order ) {
    // Generate a pseudorandom CRC32 hash using the order ID
    $order_hash = sprintf('%010d', crc32($order_id));

    return $order_hash;
}

Output

The code replaces the default WooCommerce order ID with a custom order number of 9 digits order ID. For example, instead of displaying the default order ID “1234”, it would output a unique 9-character order ID like “453672890” as the order number.

How to Set the Width of  Custom Order Number In WooCommerce? - Tyche Softwares

The above-shown custom order number doesn’t follow any sequence and it may not align with the preferences of some store owners who prioritize orders to be sequential. If so it is worth considering opting for adding sequential numbering to Order IDs. This way you can have a systematic arrangement of orders, facilitating easier tracking and management.

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