skip to Main Content

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

4

Answers


  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;
    } );
    
    Login or Signup to reply.
  2. You can do it by changing the line of code in the woocommerceincludeswc-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 ) );
    }
    
    Login or Signup to reply.
  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>';
    } );
    
    Login or Signup to reply.
  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;
    } );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search