• Resolved jrensink78

    (@jrensink78)


    In earlier versions of woocommerce, there was an option to auto-create usernames of new customers based on their email address. It would take the part before the @ symbol and that would become their username. In later versions, this option was expanded to auto-create the username based on first/last name with the email address being a fallback in the event no first/last name was available.

    I had some other processes and instructions that were geared towards the email method and the switch to using first/last name is causing some confusion (let alone having spaces in usernames when someone enters multiple names in the last name entry). I’d like to get back to just using the email method if possible, but it’s not an option in the woocommerce settings anymore.

    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 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. Is there a way to override this function with a filter that just uses the email process?

    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 );
    }`

    I tried posting this in a related topic a week ago, but I think because it’s marked resolved, I’m not getting traction there. So I figured I’d start a new topic, since it’s slightly different then what they were doing.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Stop using first/last name for customer account names’ is closed to new replies.