Last active
November 20, 2021 06:33
-
-
Save DeveloperWil/57f10f317870c86e217fb91427494512 to your computer and use it in GitHub Desktop.
WooCommerce: Custom Order Number Based On Billing Customers Initials And Random Number between 10,000 and 99,999
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generate an order ID based on the billing customers initials and a random number between 10000 and 99999 | |
* | |
* @author Wil Brown zeropointdevelopment.com | |
* @param $order_id | |
* | |
* @return string | |
* @throws Exception | |
*/ | |
function zpd_change_woocommerce_order_number( $order_id ) { | |
$order = new WC_Order($order_id); | |
$billing_first_name = strtoupper( $order->get_billing_first_name() ); | |
$billing_last_name = strtoupper( $order->get_billing_last_name() ); | |
$random_order_number = random_int(10000, 99999); | |
return $billing_first_name[0] . $billing_last_name[0] . '-' . $random_order_number; | |
} | |
add_filter('woocommerce_order_number', 'zpd_change_woocommerce_order_number'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will only apply to new orders after you have copied the code into your child theme's functions.php file so it won't touch existing orders.