简体   繁体   中英

Woocommerce - Alternative h1 title of My Account page for not logged in users

I have set up our bakeries web store in a way that any woo commerce page is only accessible for logged in users. Now I am looking for a way to change the title of h1 on the My Account page in order to display something different for not logged in users. Has anyone an idea how to achieve that? Thanks for your input! Saludos!

Wordpress has a built in function to check if a user is logged in.

<?php
    //Built in Wordpress function that checks if the user is signed in
    if ( is_user_logged_in() ) {
        //If the user is logged in
        echo '<h1>Logged in title</h1>';
    } else {
       //If user is not logged in
       echo '<h1>Not logged in title</h1>';
    }
?>

You will need to modify the Woocommerce template by overriding it.

Example: To override the admin order notification, copy: woocommerce/templates/emails/admin-new-order.php to yourtheme/woocommerce/emails/admin-new-order.php

----(Update)----

I was wrong… Woocommerce My account is a page . The <h1>page title</h1> is the title of your page, so you will need to change it, in the wordpress template for pages in your theme (Each theme is different) and not in woocommerce templates .

Once you have found this template in your theme folder, you will use a conditional in an if statement around the <h1>page title</h1> :

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

This code is just a closer example, you will need to customize it a bit…

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