'Woocommerce Edit Message "An account is already registered with your email address. Please log in."
I am looking to overwrite this message via functions.php
through a child's theme. I have seen some examples through here and here.
I would prefer using a filter but don't know why is it not working when I add it into functions.php
:
add_filter( 'woocommerce_registration_error_email_exists', function( $html ) {
$url = wc_get_page_permalink( 'myaccount' );
$url = add_query_arg( 'redirect_checkout', 1, $url );
$html = str_replace( 'Please log in', '<a href="'.$url.'"><strong>Please log in</strong></a>', $html );
return $html;
} );
Solution 1:[1]
If you want the change the entire message, use this code:
add_filter( 'woocommerce_registration_error_email_exists', function( $html ) {
$url = wc_get_page_permalink( 'myaccount' );
$url = add_query_arg( 'redirect_checkout', 1, $url );
$html = str_replace( 'An account is already registered with your email address. Please log in', '<a href="'.$url.'"><strong>YOUR CUSTOM TEXT</strong></a>', $html );
return $html;
} );
Solution 2:[2]
You can do it by changing the line of code in the woocommerce\includes\wc-user-functions.php file. =>Line 47.
after this code
if ( email_exists( $email ) ) {
return new WP_Error( 'registration-error-email-exists', apply_filters( 'woocommerce_registration_error_email_exists', __( 'An account is already registered with your email address. <a href="#" class="showlogin">Please log in.</a>', 'woocommerce' ), $email ) );
}
Solution 3:[3]
This worked for me (put in your functions.php):
/** Replace 'An account is already registered with your email address. Please log in.' **/
add_filter( 'woocommerce_registration_error_email_exists', function() {
return 'Este înregistrat deja un cont cu adresa ta de e-mail. <a href="#" class="showlogin">Te rug?m s? te autentifici.</a>';
} );
Solution 4:[4]
The complete html code includes the anchor tag as well. Add this filter in functions.php file in child theme. You can change the TEXTs as desired.
add_filter( 'woocommerce_registration_error_email_exists', function( $html ) {
$html = str_replace( 'An account is already registered with your email address. <a href="#" class="showlogin">Please log in.</a>', 'TEXT1. <a href="#" class="showlogin">TEXT2.</a>', $html );
return $html;
} );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | John |
Solution 2 | dennis_ler |
Solution 3 | Iurie |
Solution 4 | Rahul |