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;
}
function qaisar_custom_order_prefix( $orderId ) {
return 'test-'.$orderId;
}