Forum Replies Created

Viewing 1 replies (of 1 total)
  • Just to piggyback on this, since it’s very close to what I’m looking to do. How would we get back to the previous behavior of using the email address, but only the part before the @ symbol?

    I just want things to work the way that they did before, since I have some other processes/instructions that worked well based on that behavior. So digging in, I find the WC code for the auto username generation can be found in the woocommerce/includes/wc-user-functions.php file and the function is called wc_create_new_customer_username. I assume this is what is being overridden using the filter shared by Joey above.

    I figure I could just comment out the parts of the wc-user-functions.php file to skip over the first/last name portion of creating a username, leaving just the email address portion. But that’s going to get overwritten every time I update woocommerce. Would tweaking the filter from Joey be an option as well?

    Here is what the WC function is doing for the email address part. For reference, $username_parts was defined earlier in the function as shown below.

    $username_parts = array();

    // If there are no parts, e.g. name had unicode chars, or was not provided, fallback to email.
    	if ( empty( $username_parts ) ) {
    		$email_parts    = explode( '@', $email );
    		$email_username = $email_parts[0];
    
    		// Exclude common prefixes.
    		if ( in_array(
    			$email_username,
    			array(
    				'sales',
    				'hello',
    				'mail',
    				'contact',
    				'info',
    			),
    			true
    		) ) {
    			// Get the domain part.
    			$email_username = $email_parts[1];
    		}
    
    		$username_parts[] = sanitize_user( $email_username, true );
    	}
Viewing 1 replies (of 1 total)