简体   繁体   中英

Change Woocommerce "My Account" page title for unlogged users

I work on small project, and want to make this scenario to work on. I want to make when user is logged in the title of My Account page to write "My Account", and when is logged out, the title of page to write "Login Register". To explain better with images:

  1. For logged in users

在此处输入图像描述

  1. For non-logged in users

在此处输入图像描述

I have this code apply, but it seems do not change something.

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

or maybe

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

Any help?

You can use the following:

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

Code goes in function.php file of your active child theme (or active theme). Tested and works.

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