简体   繁体   English

更改我的帐户/密码丢失/页面上的Woocommerce密码丢失文本,无需覆盖模板

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

The standard text on Woocommerce Lost Password page is: Woocommerce丢失密码页面上的标准文本为:

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 标签为: 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 我在登录页面的WooCommerce注册中使用了将标签“用户名”更改为“帐号”,并尝试了以下用于丢失密码页面的其他代码

Code1 - This has no impact 代码1-这没有影响

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 - 代码2-

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. 使用gettext过滤器进行翻译可能会使您的网站变慢,因为它们针对每个可翻译字符串运行。 So you might want to look at some of the WordPress translation plugins if that's an issue for you. 因此,如果这对您来说是一个问题,那么您可能想看看一些WordPress翻译插件。

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.';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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