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

How to Set Current Year as a Prefix for WooCommerce Order Numbers?

When your store gets a lot of orders, you might need a better way to organize and track them. One such simple solution is to set the current year as a prefix appended to the WooCommerce Order IDs. This way you can easily track orders based on which year they were placed. Interested in how to do this? Look further to know how to implement this WooCommerce customization!

Solution: Set Current Year as a Prefix for WooCommerce Order Numbers

The code snippet will concatenate the current year (retrieved using date('Y')) as a prefix to the order number.

add_filter( 'woocommerce_order_number', 'ts_custom_order_number', 1, 2 );
function ts_custom_order_number( $order_id, $order ) {
    return date( 'Y' ) . $order_id; // Prefix with current year
}

Output

When an order is placed, the code tends to add the current year as a prefix to the Order ID. For example, if the order ID is 1234 and the current year is 2024, the resulting order number would be “20241234”.

How to Set Current Year as a Prefix for WooCommerce Order Numbers? - Tyche Softwares


Just like adding the date, you can also add a prefix and suffix to your WooCommerce order numbers for improved organization and identification. Want to try? Take a look at our specific post that will guide you to add a prefix and suffix to your WooCommerce order numbers.

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

Share It:

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