Change My Account Entry Title Dynamically

Hello, on my website running WooCommerce and X Theme Pro, I want to change the entry title of the My Account page to a greeting based on the logged-in user’s role. Can I do this by adding code to my child theme’s functions.php?

For the customer user role, I want it to say Welcome, Customer!
For the distributor user role, I want it to say Welcome, Distributor!

If not, can I disable the entry title then add in the custom greeting?

Please let me know how this can be done, thank you!

Hello @jessebrito,

Thanks for writing in!

Changing account title based on account type will require custom development work which falls outside the scope of support we can offer. However, you can take a look at following resources to get started:

Thanks.

Hello @Prasant,

I checked those links are they are for changing titles of the My Account endpoints like Dashboard, Orders, Downloads, Addresses, etc. I want to change the entry title which is the page title (My Account).

If that’s not possible, any advice for adding HTML content to the start of the div .entry-content of the page?

Hi @jessebrito,

While that is outside the scope of support, I could point you in the right direction with the understanding that it would ultimately be your responsibility to take it from here.

The page title h1.entry-title is on this file content-page.php under \framework\views\{stack name} copy that file to your child theme (same directory) and do your modification in there.

Then use the Conditional Tags provided here to show different title on different Woocommerce page/endpoints.

Cheers!

Hello @friech,

Thank you, that content-page.php file is exactly what I needed. Once I moved it to my child theme I added the following code on Line 23:

<?php
if ( is_user_logged_in() && is_account_page() ) {
  $user = wp_get_current_user();
    if ( in_array('distributor', (array) $user->roles) ) {
    ?>
      <h1 class="entry-title greeting">Welcome, Distributor!</h1>
    <?php
    } else if ( in_array('customer', (array) $user->roles) ) {
    ?>
      <h1 class="entry-title greeting">Welcome, Customer!</h1>
    <?php
  }
} else {
  ?>
  <h1 class="entry-title"><?php the_title(); ?></h1>
  <?php
}
?>

This way, when a user is logged in and on the My Account page, the entry title will change to greet whichever user role they are.

Thank you for your help!

Hey @jessebrito,

We are just glad that you have figured it out a way to correct the said issue.
Thanks for letting us know!

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.