When people are buying a product through the WooCommerce extension, I have enabled that they can create an account on checkout. I don’t let them choose their own username and password.
Now I see that WP uses some part of the emailaddress to create a username, and the display name is based on the first name filled in on checkout.
Now I want to change that:
- username must be the complete emailaddress [SOLVED];
- display name must be the first name + last name [UNSOLVED].
I tried this: for display name with my ‘no knowledge’ of PHP:
add_filter('pre_user_display_name', 'wsis_pre_user_display_name');
function wsis_pre_user_display_name($display_name) {
$first = get_user_field("billing_first_name");
$last = get_user_field("billing_last_name");
$display_name = $first . $last;
return $display_name;
}
This filter is mentioned in their codex: http://codex.wordpress.org/Function_Reference/wp_update_user. But no examples and my code didn’t work. Anybody can help?
In user.php wp-includes folder I found the filter, now get it working :-).
/**
* Filter a user's display name before the user is created or updated.
*
* @since 2.0.3
*
* @param string $display_name The user's display name.
*/
$display_name = apply_filters( 'pre_user_display_name', $display_name );
if ( empty($description) )
$description = '';
Second try did something! It left the display name completely empty:
add_filter('pre_user_display_name', 'pre_user_display_name');
function pre_user_display_name($display_name) {
$first = get_the_author_meta('first_name');
$last = get_the_author_meta('last_name');
$display_name = $first . $last;
return $display_name;
}
Am I on the right track?
To set the username as complete email address, you can add following code in functions.php file of your theme.
Here is how to set the display name to first name + last name.
Source : http://geektamin.com/blog/533/why-update_user_meta-display_name-doesnt-work-and-how-to-use-pre_user_display_name-instead/