WooCommerce PHP Beginner Requires WooCommerce

Add a Prefix to Order Numbers

Show order numbers like "NP-1234" instead of "1234" in emails, My Account and wp-admin.

Tested on WordPress 7.1 PHP 8.3 Updated
functions.php 3 lines
add_filter( 'woocommerce_order_number', function ( $number ): string {
	return 'NP-' . $number;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

A prefix makes your order numbers recognisable in customers’ inboxes and in your accounting software, and stops them looking like low, sequential numbers.

How it works

Everywhere WooCommerce displays an order number, it calls $order->get_order_number(), which passes the order id through the woocommerce_order_number filter. Adding a prefix there changes it in emails, the thank-you page, My Account and the orders list.

Things to watch

  • The order’s real id is unchanged, so URLs and integrations that use the id keep working.
  • Searching orders in wp-admin by “NP-1234” won’t find them. Search by the number alone.
  • Some payment and accounting plugins read the order number; check that they show it correctly.

How to test it

Place a test order. The thank-you page and confirmation email should show “NP-” before the number.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only