我想在Woocommerce注册页面上删除用户名字段,我该怎么做?或者如何将用户电子邮件用作用户名,或者不要求使用用户名字段?任何帮助,将不胜感激。非常感谢。
答案 0 :(得分:0)
是的,这是可能的。请正确执行以下步骤。
步骤1:删除用户名文本字段
add_action('login_head', function(){
?>
<style>
#registerform > p:first-child{
display:none;
}
</style>
<script type="text/javascript" src="<?php echo site_url('/wp-includes/js/jquery/jquery.js'); ?>"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#registerform > p:first-child').css('display', 'none');
});
</script>
<?php
});
步骤2:删除用户名错误
//Remove error for username, only show error for email only.
add_filter('registration_errors', function($wp_error, $sanitized_user_login, $user_email){
if(isset($wp_error->errors['empty_username'])){
unset($wp_error->errors['empty_username']);
}
if(isset($wp_error->errors['username_exists'])){
unset($wp_error->errors['username_exists']);
}
return $wp_error;
}, 10, 3);
步骤3:操纵背景注册功能。
add_action('login_form_register', function(){
if(isset($_POST['user_login']) && isset($_POST['user_email']) && !empty($_POST['user_email'])){
$_POST['user_login'] = $_POST['user_email'];
}
});
将以上代码放在主题的functions.php文件中。