簡體   English   中英

更改我的帳戶/密碼丟失/頁面上的Woocommerce密碼丟失文本,無需覆蓋模板

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

Woocommerce丟失密碼頁面上的標准文本為:

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

標簽為: Username or email

我在登錄頁面的WooCommerce注冊中使用了將標簽“用戶名”更改為“帳號”,並嘗試了以下用於丟失密碼頁面的其他代碼

代碼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;
}

代碼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; 
}}

這有效但是搞砸了登錄頁面-請參見下面的屏幕截圖 混亂的登錄頁面

任何幫助,將不勝感激。 謝謝

現有代碼可以有效地將每個可翻譯字符串轉換為空結果,從而使您獲得的頁面內容大部分為空白。 與此更接近的方法應該起作用:

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

使用gettext過濾器進行翻譯可能會使您的網站變慢,因為它們針對每個可翻譯字符串運行。 因此,如果這對您來說是一個問題,那么您可能想看看一些WordPress翻譯插件。

編輯:和用於更改說明文字的代碼段:

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