Website Building » WooCommerce » How Do I Create a Custom Order Number in WooCommerce?

How Do I Create a Custom Order Number in WooCommerce?

Last updated on January 18, 2023 @ 6:26 pm

If you have a WooCommerce store, you’ve probably noticed that your order numbers are automatically generated by WooCommerce. While this is great for most stores, some store owners may want to create their own custom order numbers.

There are a few different ways to create custom order numbers in WooCommerce. One way is to use a plugin like Sequential Order Numbers for WooCommerce.

This plugin allows you to set your own custom order number prefix, suffix, and starting number. This is a great option if you want more control over your order numbers.

Another way to create custom order numbers is to add a snippet of code to your functions.php file. This method requires a bit more technical knowledge, but it gives you more control over how your order numbers are generated. If you’re not comfortable editing code, we recommend using the Sequential Order Numbers for WooCommerce plugin.

PRO TIP: If you are not a developer, or are not comfortable working with code, we recommend that you seek help from a developer before proceeding with this tutorial. Making changes to your WooCommerce order numbers can have unintended consequences on your store if not done correctly.

If you want to create custom order numbers using code, you can add this snippet to your functions.php file:

function wc_custom_order_numbers( $order_id ) {
    $order = new WC_Order( $order_id );
    $order->update_meta_data( '_order_number', '123' ); //Change 123 to your desired order number
    $order->save();  }
add_action( 'woocommerce_checkout_update_order_meta', 'wc_custom_order_numbers' );

You can also use this code snippet to set the starting number for your custom order numbers:

function wc_custom_order_numbers() {
    $count = get_option( 'wc_customOrderNumbers_startNumber', false ); //Change 123 to your desired starting number

    if ( $count !== false ) { 	 	 	  	 	 	  	 	       update_option( 'wc_customOrderNumbers__startNumber', ++$count ); } else { update_option( 'wc-customOrderNumbers__startNumber', 1 ); } } add_action( 'woocommerce-new-order', 'wc-customOrderNumbers' );

Conclusion: There are a few different ways that you can create custom order numbers in WooCommerce. Otherwise, you can add a snippet of code to your functions.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.