How to Create Custom or Sequential Order Numbers Programmatically

Today we are going to discuss how we can create custom or sequential order numbers programmatically in WooCommerce. Understand one thing before starting, that order number and order ID are not the same terms in WooCommerce.

 

  • Add custom prefix or suffix text with order number
  • Include order dates into order numbers

Use  woocommerce_order_number filter hook to change order numbers. You can also add date format {number}-{Year}. (code below)

  • Include sub-site IDs for orders. 

 

Sequential Order Numbers

So the whole idea of sequential order numbers comes into two parts. In the first part, we need to create a custom field when an order is created.

In the second part, we are using a custom field value as an order number.

add_filter( 'woocommerce_order_number', 'qaisar_custom_order_prefix' );

function qaisar_custom_order_prefix( $orderId ) {

return 'test-'.$orderId;

}

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!