为未登录用户更改 Woocommerce "My Account" 页面标题

Change Woocommerce "My Account" page title for unlogged users

我在做一个小项目,想让这个场景继续工作。我想在用户登录时将“我的帐户”页面的标题写为“我的帐户”,并在注销时将页面标题写为“登录注册”。为了更好地解释图像:

  1. 对于 登录 用户

  1. 对于non-logged用户

我应用了这段代码,但似乎没有改变什么。

function dynamic_label_change( $items, $args ) { 
 if ( ! is_user_logged_in() ) { 
  $items = str_replace( "My Account", "Account Login / Register ", $items ); 
 } 
 return $items; 
} 

或者也许

// When user is on my account page and not logged in
if (is_account_page() && !is_user_logged_in()) {
echo '<h1 class="entry-title">'.__("My custom title", 
"the_theme_slug").'</h1>'; // My custom title
} else {
 the_title( '<h1 class="entry-title">', '</h1>' ); // the normal template 
title
}

有什么帮助吗?

您可以使用以下内容:

add_filter( 'the_title', 'display_product_image_in_order_item' );
function display_product_image_in_order_item( $title ) {
    if( is_account_page() && $title === __('My Account', 'woocommerce') && ! is_user_logged_in() ) {
        $title = __( 'Account Login / Register', 'woocommerce' );
    }
    return $title;
}

代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。