Hi!
I don’t think WooCommerce has a straight setting to do this.
You can add this code snippet in your themes’s functions.php and you should be good to go.
The solution takes care of both front-end and back-end and displays an error to the user that their email cannot be modified.
add_action( 'woocommerce_after_edit_account_form', 'disable_edit_email_address' );
function disable_edit_email_address( ) {
$script = '<script type="text/javascript">'.
'var account_email = document.getElementById("account_email");'.
'if(account_email) { '.
' account_email.readOnly = true; '.
' account_email.className += " disable-input";'.
'}'.
'</script>';
echo $script;
}
add_action( 'woocommerce_save_account_details_errors', 'prevent_user_update_email', 10, 2 );
function prevent_user_update_email( &$error, &$user ){
$current_user = get_user_by( 'id', $user->ID );
$current_email = $current_user->user_email;
if( $current_email !== $user->user_email){
$error->add( 'error', 'E-mail cannot be updated.');
}
}
I would recommend that you do this only if you are somewhat comfortable in adding code.
This will prevent customers from editing their email themselves, but you can still edit users email if necessary from wp-admin->users.
Thanks ??
-
This reply was modified 4 years, 10 months ago by
Priya Gupta.