Menu Close

WooCommerce: Order Number Prefix / Suffix

default

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!

In this example, I’ve added a prefix “BB-” in front of the order numbers. I can see the change here in the Order table, and also in the quick view window (eye icon), the single order page, and the My Account > My orders page

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        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_order_number', 'bbloomer_order_number_prefix', 9999, 2 );

function bbloomer_order_number_prefix( $order_id, $order ) {
	return 'Prefix-' . $order_id . '-suffix';
}
View Source
Posted in WooCommerce Tips