简体   繁体   中英

Change Woocommerce Lost Password text on my-account/lost-password/ page without template override

The standard text on Woocommerce Lost Password page is:

Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.

The label is: Username or email

I have used Change label “username” to “account number” in WooCommerce registration for the Login page and tried additional codes below for the lost password page

Code1 - This has no impact

add_filter( 'gettext', 'change_lost_usename_label', 10, 3 );
function change_lost_usename_label( $translated, $text, $domain ) {
    if( is_lost_password_page() && ! is_wc_endpoint_url() ) {
            if( $text === 'username or' ) {
            $translated = __( 'Registered', $domain );
        }
    }
    return $translated;
}

Code2 -

add_filter('gettext', 'change_lost_password' );
function change_lost_password($translated) {
    if( is_lost_password_page() ) {
  $translated = str_ireplace('username or email', 'Registered email', $translated);
  return $translated; 
}}

This works BUT messes up Login Page - See screenshot below 混乱的登录页面

Any help would be appreciated. Thanks

The existing code is effectively translating every translatable string to an empty result, leaving you with the mostly-blank page content you're seeing. Something closer to this should work:

add_filter('gettext', 'change_lost_password' );
function change_lost_password($translated) {
   if( is_lost_password_page() && 'Username or email' === $translated) {
      return 'Registered email';
   } else {
      return $translated; 
   }
}

Translating with gettext filters might slow your site down a bit though because they run for every translatable string. So you might want to look at some of the WordPress translation plugins if that's an issue for you.

Edit: and a snippet for changing the explanatory text:

add_filter('woocommerce_lost_password_message', 'change_lost_password_message');
function change_lost_password_message() {
    return 'Lost your password? Please enter your registered email address. You will receive a link to create a new password via email.';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM