As you know WooCommerce uses the “order ID” (which is also the ID of the order post in the database) as the order number. This displays in the “WooCommerce” > “Orders” table, on each line of the order, under the “Order ” column, as well as the order “quick view” window, the single order page and the customer’s My Account page.
But what if you need to add a prefix or a suffix to this number, so that this is in line with your business or invoice requirements?
Here’s the fix – enjoy!

PHP Snippet: Add Prefix and/or Suffix to WooCommerce Order Numbers
In the snippet below, I’m simply adding text before and after the order ID. Simply edit or remove the strings to display prefix and/or suffix.
/**
* @snippet Order Number Prefix/Suffix
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 8
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_order_number', 'bbloomer_order_number_prefix', 9999, 2 );
function bbloomer_order_number_prefix( $order_id, $order ) {
return 'Prefix-' . $order_id . '-suffix';
}
Hi Rodolfo,
Is there a way to add a prefix to the order number based on the product category?
So,
if (cat_1) prefix = AB
if (cat_2) prefix = CD
Thanks.
Hello Fred, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi! Thank you for the code. We currently use a plugin for this which keeps the order id and creates a new custom one as well.
Does this code change the order id’s in the database as well? If the code is removed in the future, what happens?
Nope this is only a “display” change, nothing will be edited in the DB. If you remove the snippet you go back to the default display.