How to Change WooCommerce Order Number – 2026

Last updated on October 30th, 2024 at 09:54 am

By default, WooCommerce uses the WordPress post ID as the order number. While this works for basic stores, some businesses may need more customised order numbers to align with internal processes or customer expectations. In this guide, we’ll show you how to change WooCommerce order numbers without a plugin by using custom code.

As always, it’s best to make these changes in a child theme to ensure your modifications aren’t lost during theme updates.


Why Change WooCommerce Order Numbers?

Here are some common reasons why you might want to customise order numbers:

  • Internal Tracking: Align order numbers with an external system (e.g., accounting or fulfilment software).
  • Security and Privacy: Avoid exposing the number of orders you’ve processed.
  • Improved Customer Experience: Use more intuitive order numbers to make tracking easier for customers.

Step 1: Add a Custom Prefix or Suffix to Order Numbers

The following code adds a prefix or suffix to order numbers for better organisation. Add it to your theme’s functions.php file or use a child theme.

/*
 * Snippet: How to Change WooCommerce Order Number – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1591
* Tested with WooCommerce 10.7.0
* "This function adds a prefix and suffix to WooCommerce order numbers"
*/ function wcsuccess_custom_order_number( $order_id ) { $prefix = 'WC-'; $suffix = '-2024'; return $prefix . $order_id . $suffix; } add_filter( 'woocommerce_order_number', 'wcsuccess_custom_order_number' );

How This Works

  • woocommerce_order_number Filter: This filter allows you to modify the order number format.
  • Prefix and Suffix: Adds ‘WC-‘ as the prefix and ‘-2024’ as the suffix to each order number. You can change these values as needed.

Step 2: Generate Sequential Order Numbers

If you want to avoid gaps in order numbers (caused by deleted orders), you can create sequential order numbers. Here’s how:

/*
 * Snippet: How to Change WooCommerce Order Number – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1591
* Tested with WooCommerce 10.7.0
* "This function generates sequential WooCommerce order numbers"
*/ function wcsuccess_sequential_order_number( $order_id ) { $last_order_number = get_option( 'wcsuccess_last_order_number', 1000 ); // Start from 1001 $new_order_number = $last_order_number + 1; update_option( 'wcsuccess_last_order_number', $new_order_number ); return $new_order_number; } add_filter( 'woocommerce_order_number', 'wcsuccess_sequential_order_number' );

How This Works

  • Sequential Logic: The code stores the last order number in the WordPress options table and increments it by one for each new order.
  • Starting Point: You can change the starting order number by modifying the initial value (1000).
See also  How to Customise the WooCommerce Order Confirmation Email with Product-Specific Messages - 2026

Step 3: Use Shortcodes to Display Custom Order Numbers

If you need to display order numbers with specific formatting dynamically, use the do_shortcode() function.

/*
 * Snippet: How to Change WooCommerce Order Number – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1591
* Tested with WooCommerce 10.7.0
* "This shortcode displays custom WooCommerce order numbers"
*/ function wcsuccess_display_custom_order_number( $atts ) { global $wp; $order_id = wc_get_order_id_by_order_key( $wp->query_vars['order-received'] ); return 'Order Number: ' . do_shortcode( '[your_custom_shortcode id="' . $order_id . '"]' ); } add_shortcode( 'display_custom_order', 'wcsuccess_display_custom_order_number' );

How This Works

  • Retrieve Order ID: The shortcode dynamically retrieves the order ID.
  • Shortcode Flexibility: You can insert the shortcode on pages or in email templates to display custom order numbers.

Step 4: Update Order Numbers in WooCommerce Emails

To display the new order number format in WooCommerce emails, modify the following template function in functions.php.

/*
 * Snippet: How to Change WooCommerce Order Number – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1591
* Tested with WooCommerce 10.7.0
* "This function modifies order numbers in WooCommerce emails"
*/ function wcsuccess_modify_email_order_number( $order, $sent_to_admin, $plain_text ) { echo 'Order Number: ' . apply_filters( 'woocommerce_order_number', $order->get_id() ); } add_action( 'woocommerce_email_order_details', 'wcsuccess_modify_email_order_number', 10, 3 );

How This Works

  • Email Modification: Displays the custom order number format in all outgoing WooCommerce order emails.
  • Filter Integration: Uses the woocommerce_order_number filter to ensure consistency across the site.

Best Use Cases for Customising Order Numbers

  • Align with External Systems: Sync WooCommerce orders with fulfilment or accounting systems using specific order formats.
  • Streamline Customer Communication: Use sequential numbers or meaningful prefixes for improved clarity in order tracking.
  • Enhanced Security: Mask real order volumes by using non-sequential or formatted order numbers.
See also  How to Split Variable Products Into Simple Products Without a Plugin in WooCommerce - 2026

Conclusion

Changing WooCommerce order numbers allows you to align them with your store’s needs and improve both internal operations and customer communication. Whether you’re adding prefixes, generating sequential numbers, or modifying email templates, these customisations give you full control over how order numbers are handled.

Remember to test your changes in a staging environment before applying them to your live site. Use a child theme to protect your customisations. For more WooCommerce tips, check out our WooCommerce Visual Hooks Guide and wp-config generator for further enhancements.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top
0
Would love your thoughts, please comment.x
()
x
×