How to Add a Prefix to Your WooCommerce Order Numbers
You may want to add a prefix to your WooCommerce order numbers to make them easier to identify or match your internal processes. This simple code snippet lets you do that safely, without affecting your existing orders or subscriptions.
PHP
12345678
add_filter( 'woocommerce_order_number', 'ag_add_prefix_to_order_number', 10, 2 );
function ag_add_prefix_to_order_number( $order_number, $order ) {
$prefix = 'AG-'; // Change this to whatever prefix you want
return $prefix . $order_number;
}How to use it:
Copy the code snippet provided above.
Add it to your site safely, either in a child theme’s
functions.phpfile or using a code snippet plugin.Save and check your orders, the prefix should now appear in your order numbers.
Was this helpful?