Woocommerce 编辑消息“帐户已使用您的电子邮件地址注册。请登录。”

w_l*_*lpz 2 php wordpress woocommerce

我希望通过functions.php儿童主题覆盖此消息。我在这里和这里看到了一些例子。

我更喜欢使用过滤器,但不知道为什么当我将其添加到时它不起作用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;
} );
Run Code Online (Sandbox Code Playgroud)

Joh*_*ohn 5

如果您想更改整个消息,请使用以下代码:

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;
} );
Run Code Online (Sandbox Code Playgroud)