This simple WooCommerce customization is specifically for stores with a large customer base or multiple email domains. Discover how this simple code snippet lets you add customer email domains to WooCommerce Order IDs.
Solution: Add Email Domain to WooCommerce Custom Order Numbers
The code retrieves the customer’s email address associated with the order, extracts the domain part of the email address, and then generates a random number between 1000 and 9999. Finally, it concatenates the domain with the random number to create a unique order number.
add_filter( 'woocommerce_order_number', 'ts_add_customer_email_domain_to_random_order_number', 1, 2 ); function ts_add_customer_email_domain_to_random_order_number( $order_id, $order ) { // Get customer email $customer_email = $order->get_billing_email(); // Extract domain from email $email_parts = explode( '@', $customer_email ); $domain = isset( $email_parts[1] ) ? $email_parts[1] : ''; // Generate a random order number $random_number = rand( 1000, 9999 ); // Concatenate domain with random number $order_number_with_domain = $domain . '-' . $random_number; return $order_number_with_domain; }
Output
The code tends to modify the WooCommerce Order numver by adding a random order number along with the customer’s email domain name.
![](https://www.tychesoftwares.com/wp-content/uploads/2024/05/Email-domain-added-to-Custom-Order-Numbers-1024x496.png)
Similarly, you can add several personalized touches to your WooCommerce order numbers. For instance, you can add customers’ initials to the order number.