Last active
February 27, 2020 00:09
-
-
Save NickGreen/05a2d16233d39f71fde48bee46972820 to your computer and use it in GitHub Desktop.
Create username from email, just using the part before the "@"
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
| <?php | |
| add_filter( 'woocommerce_new_customer_data', 'customer_username_based_on_email', 20, 1 ); | |
| function customer_username_based_on_email( $new_customer_data ){ | |
| // get the first billing name | |
| if(isset($_POST['billing_email'])) $billing_email = $_POST['billing_email']; | |
| if( ! empty($billing_email) && ! in_array( $_POST['billing_email'] ) ){ | |
| // Replacing 'user_login' in the user data array, before data is inserted | |
| $arr = explode("@", $billing_email, 2); | |
| $first_part = $arr[0]; | |
| $new_customer_data['user_login'] = $first_part; | |
| } | |
| return $new_customer_data; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment