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

How to Add WooCommerce Order Numbers with Date Prefix?

This WooCommerce customization is especially helpful for site owners who handle a high volume of orders daily or rely heavily on order dates for their business operations. In both scenarios, the code allows admins to quickly identify and sort orders based on which dates they were placed, making order management much easier. Try this feature to simplify managing your orders.

Solution: How to Add WooCommerce Order Numbers with Date Prefix

The code alters the order numbers by appending the date of creation along with the order IDs, utilizing a hyphen to separate them.

add_filter( 'woocommerce_order_number', 'ts_change_woocommerce_order_number', 1, 2 );
function ts_change_woocommerce_order_number( $order_id ) {
    $order = wc_get_order( $order_id );
    $order_date = $order->get_date_created();
    $display_date = $order_date->date('Y/m/d'); // Format date as 'y/m/d'
    $new_order_id = $display_date . '-' . $order_id; // Add a hyphen between date and order ID
    return $new_order_id;
}

Output

When a new order is created, it retrieves the order’s creation date and formats it as ‘Y/m/d’ (Year/Month/Day). Then, it adds the date as a prefix to the new order ID separated by a hyphen. 

How to Add WooCommerce Order Numbers with Date Prefix? - Tyche Softwares


Do you want to add custom order number and make the order numbers more personalized by adding customer details to it? No worries. You can check out this post that will add custom order number based on customers initials.

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