Documentation

How to Add a Prefix to Your WooCommerce Order Numbers

We’ve put this guide together as a little helping hand for developers and designers. You’ll need a basic understanding of PHP to make the most of it.

Just a quick heads-up, we can’t provide support for custom code or offer any bespoke tweaks. Think of the snippets below as examples to guide you in the right direction.

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:

  1. Copy the code snippet provided above.

  2. Add it to your site safely, either in a child theme’s functions.php file or using a code snippet plugin.

  3. Save and check your orders, the prefix should now appear in your order numbers.


Was this helpful?

Still need help?

Our team are on hand to provide fast, helpful and professional support.

Support request
All systems operational