Changing the Login/Register to user account when signed in

Hi Kharis,

Looks like the ‘my account’ only works when I’m logged in! So, if I’m not logged in, I see: login/register.

Could you help again? :slight_smile:

Greets
Heleen

Hello Heleen,

Please try removing these lines of code:

  if( !is_user_logged_in() ) {
    return;
  }

Regards,
Kharis

Thanks, the my account now works when I’m not logged in! Great!

But now the text :slight_smile: Where do I put this code that you gave me? ->

(function($){

  if( wc_pages.my_account != '' && $('.nav-link-account a').length ) {
    $('.nav-link-account a').attr('href', wc_pages.my_account).text('My Account');
  }

})(jQuery);

You can implement that code with the TC Custom JavaScript plugin.

Regards,
Kharis

Is this possible to get done as a permanent change applied to a child theme, instead of a jquery function run on top?

Another question, how do I localize i WPML the “My Account”? The link localizes well, but the name itself shows “My Account” no matter what langauge is currently set.

Hello there,

View full source code of your site and note the value of language attribute value in HTML tag located at the most top line.

22%20AM

Use this code to translate My Account text.

    (function($){

      var lang    = $('html').attr('lang');

      var myAccountLabel = 'My Account';


      // Translate 1 for English US.
      if( lang == 'en-US' ) {
        var myAccountLabel = 'My Account 1';
      }

      // Translate 2 for Italian
      if( lang == 'it-IT' ) {
        var myAccountLabel = 'My Account 2';
      }


      if( wc_pages.my_account != '' && $('.nav-link-account a').length ) {
        $('.nav-link-account a').attr('href', wc_pages.my_account).text(myAccountLabel);
      }

    })(jQuery);

Regards,
Kharis

That’s awesome. Thanks! Works great.

Sorry for bothering you but can you please clarify, is there a way to accomplish that without additional Jquery plugin?

Hello there,

Great! You’re welcome!

There might be other way, but not sure if it’s simpler that jQuery code solution.

Regards,
Kharis

@kharisblank

This is my old/current child theme functions.php:

<?php

function enqueue_parent_styles() {
	wp_enqueue_style('parent-theme', get_template_directory_uri() .'/style.css');
}
add_action('wp_enqueue_scripts', 'enqueue_parent_styles');

// global store notice override
remove_action( 'wp_footer', 'woocommerce_demo_store' );
add_action('leto_before_page', 'woocommerce_demo_store', 9);

    /**
     * Get WC page URL
     */
    add_action( 'wp_enqueue_scripts', 'leto_child_wc_pages', 9999 );
    function leto_child_wc_pages() {

      $wc_pages = array(
        'my_account' => get_permalink( wc_get_page_id( 'myaccount' ) ),
      );

      wp_localize_script( 'leto-main', 'wc_pages', $wc_pages );

    }

When I copy it to the new theme functions.php, I get:

Fatal error: Cannot redeclare leto_recommended_plugins() (previously declared in /usr/home/sin/domains/shop.sin.org.pl/public_html/wp-content/themes/leto-child/functions.php:240) in /usr/home/sin/domains/shop.sin.org.pl/public_html/wp-content/themes/leto/functions.php on line 240

Front end stops working. If I remove the file, I lose formatting. How to implement my functions.php in Leto 1.0.10? Thank you for your help!