Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins

How to Include Custom Order Number Based On Customers Initials ?

This WooCommerce customization will be helpful by generating order IDs with randomized elements such as customers’ initials, adding a touch of uniqueness to the purchasing process. Ready to take your store to the next level with more personalization options? Keep reading to discover how!

Solution: Custom Order Number Based On Customers Initials

The code extracts the initial letters from the first and last names of the customers linked to the order. It then capitalizes them to create the customer’s initials. After that, it generates a random 5-digit number and combines the initials and the random number with a hyphen in between.

add_filter( 'woocommerce_order_number', 'ts_custom_order_number', 1, 2 );

function ts_custom_order_number( $order_id, $order ) {
    $first_name = $order->get_billing_first_name();
    $last_name = $order->get_billing_last_name();
    // Get the initials of both first and last names
    $initials = strtoupper( substr( $first_name, 0, 1 ) . substr( $last_name, 0, 1 ) );
    // Generate a random 5-digit number
    $random_number = str_pad( mt_rand( 10000, 99999 ), 5, '0', STR_PAD_LEFT );

    return  $initials . '-' . $random_number;
Custom Order Number based on Customer Initials

On the other hand, if you want to simplify this customization, you can simply Create Random Custom Order Numbers in WooCommerce, which makes your order numbers highly secure and very unique.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x