Change “My Acoount” text to username

This topic has 10 replies, 3 voices, and was last updated 5 years, 9 months ago ago by Rose Tyler

  • Avatar: Sahar
    Sahar
    Participant
    February 4, 2019 at 06:50

    Hello, I would like to change “My Acoount” text and display username when is logged in. How Can I do this?
    Thanks

    9 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    February 4, 2019 at 09:18

    Hello,

    This requests additional customization in files.
    Copy etheme_sign_link function from xstore/framework/theme-functions.php to functions.php of your child theme. Add this code

    $current_user = wp_get_current_user();
    			$username = !empty($current_user->user_login) ? $current_user->user_login : esc_html__( 'My Account', 'xstore' );

    here – http://prntscr.com/mgbddf
    and change this line https://prnt.sc/mgbdsa to
    'title' => $username, https://prnt.sc/mgbe7y

    Regards

    Avatar: Sahar
    Sahar
    Participant
    February 4, 2019 at 13:19

    Great! Thank you so much for your prompt support.

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    February 4, 2019 at 13:26

    You’re welcome!

    Regards

    Avatar: Tagbag
    Tagbag
    Participant
    February 6, 2019 at 01:50

    Hey Rose,

    i tried the same, but im inexperienced. Have i to add the code of theme-functions.php into the function.php or have I just to copy the theme-functions.php into the child-theme folder?

    I am really sorry..

    Regards

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    February 6, 2019 at 08:40

    Hello @Tagbag,

    Please add this code in functions.php of your child theme:

    function etheme_sign_link($class = '', $short = false, $echo = false) {
            $link = array();
            $type = etheme_get_option( 'sign_in_type' );
            $ht = get_query_var( 'et_ht', 'xstore' );
            $login_link = (etheme_woocommerce_installed()) ? wc_get_page_permalink( 'myaccount' ) : wp_login_url();
    
            if ( $ht == 'hamburger-icon' || $type == 'icon' ) {
                $class .= ' type-icon';
            } elseif( $type == 'text_icon' ){
                $class .= ' type-icon-text';
            }
    
            if ( is_user_logged_in() && etheme_woocommerce_installed() ) {
    
            	$current_user = wp_get_current_user();
    			$username = !empty($current_user->user_login) ? $current_user->user_login : esc_html__( 'My Account', 'xstore' );
    
                    if ( has_nav_menu( 'my-account' ) ) { 
                        $submenu = wp_nav_menu(array(
                            'theme_location' => 'my-account',
                            'before' => '',
                            'container_class' => 'menu-main-container',
                            'after' => '',
                            'link_before' => '',
                            'link_after' => '',
                            'depth' => 100,
                            'fallback_cb' => false,
                            'walker' => new ETheme_Navigation,
                            'echo' => false
                        ));
                    } else {
                        $submenu = '<div class="menu-main-container">';
                            $submenu .= '<ul class="menu">';
                                foreach ( wc_get_account_menu_items() as $endpoint => $label ) {
                                    $url = ( $endpoint != 'dashboard' ) ? wc_get_endpoint_url( $endpoint, '', $login_link ) : $login_link ;
                                    $submenu .= '<li class="' . wc_get_account_menu_item_classes( $endpoint ) . '">';
                                        $submenu .= '<a href="' . esc_url( $url ) . '">' . esc_html( $label ) . '</a>';
                                    $submenu .= '</li>';
                                }
                            $submenu .= '</ul>';
                        $submenu .= '</div>';
                    }
    
                    $link = array(
                        'class' => 'my-account-link' . $class,
                        'link_class' => '',
                        'href' => $login_link,
                        'title' => $username,
                        'submenu' => $submenu
                    );
                    $class .= ' my-account-link';
            } else {
                $login_text = ( $short ) ? esc_html__( 'Sign In', 'xstore' ) : esc_html__( 'Sign In or Create an account', 'xstore' );
                $login_text = ( etheme_get_option( 'sign_in_text' ) != '' ) ? etheme_get_option( 'sign_in_text' ) : $login_text;
    
                if ( ! $short ) {
                    if ( etheme_woocommerce_installed() ) { 
                        ob_start(); ?>
                        <form class="woocommerce-form woocommerce-form-login login" method="post" action="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ) ?>">
    
                            <?php do_action( 'woocommerce_login_form_start' ); ?>
    
                            <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                                <label for="username"><?php esc_html_e( 'Username or email address', 'xstore' ); ?>&nbsp;<span class="required">*</span></label>
                                <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="username" autocomplete="username" value="<?php echo ( ! empty( $_POST['username'] ) ) ? esc_attr( wp_unslash( $_POST['username'] ) ) : ''; ?>" /><?php // @codingStandardsIgnoreLine ?>
                            </p>
                            <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                                <label for="password"><?php esc_html_e( 'Password', 'xstore' ); ?>&nbsp;<span class="required">*</span></label>
                                <input class="woocommerce-Input woocommerce-Input--text input-text" type="password" name="password" id="password" autocomplete="current-password" />
                            </p>
    
                            <?php do_action( 'woocommerce_login_form' ); ?>
    
                            <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" class="lost-password"><?php esc_html_e( 'Lost password ?', 'xstore' ); ?></a>
    
                            <p>
                                <label class="woocommerce-form__label woocommerce-form__label-for-checkbox inline">
                                    <input class="woocommerce-form__input woocommerce-form__input-checkbox" name="rememberme" type="checkbox" id="rememberme" value="forever" /> <span><?php esc_html_e( 'Remember Me', 'xstore' ); ?></span>
                                </label>
                            </p>
    
                            <p class="login-submit">
                                <?php wp_nonce_field( 'woocommerce-login', 'woocommerce-login-nonce' ); ?>
                                <button type="submit" class="woocommerce-Button button" name="login" value="<?php esc_attr_e( 'Log in', 'xstore' ); ?>"><?php esc_html_e( 'Log in', 'xstore' ); ?></button>
                            </p>
                            <?php if ( get_option( 'woocommerce_enable_myaccount_registration' ) === 'yes' ): ?>
                                <p class="text-center"><?php esc_html_e('New client', 'xstore');?> <a href="<?php echo $login_link; ?>" class="register-link"><?php esc_html_e('Register ?', 'xstore'); ?></a></p>
                            <?php endif; ?>
    
                            <?php do_action( 'woocommerce_login_form_end' ); ?>
    
                        </form>
    
                    <?php $login_form = ob_get_clean(); }
                    else {
                        $login_form = wp_login_form(
                            array(
                                'echo' => false,
                                'label_username' => esc_html__( 'Username or email address *', 'xstore' ),
                                'label_password' => esc_html__( 'Password *', 'xstore' )
                            )
                        );
                    }
                } else {
                    $login_form = '';
                }
                $link = array(
                    'class' => 'login-link' . $class,
                    'link_class' => '',
                    'href' => $login_link,
                    'title' => $login_text,
                    'submenu' => '<div class="menu-main-container">' . $login_form . '</div>'
                );
    
                $class .= ' login-link';
            }
    
            if ( $echo ) {
                $out = '';
                $out .= sprintf(
                    '<%1$s class="%2$s"><a href="%3$s" class="%4$s">%5$s</a>%6$s</%1$s>',
                    ( etheme_get_option( 'top_links') == 'menu' ) ? 'li' : 'div',
                    $class,
                    $link['href'],
                    $link['link_class'],
                    $link['title'],
                    $link['submenu']
                );
                if ( $echo === 'get' ) {
                    return $out;
                } else {
                    echo $out;
                }
            } else {
                return $link;
            }
        }

    Let me know the result.

    Regards

    Avatar: Tagbag
    Tagbag
    Participant
    February 6, 2019 at 09:07

    awesome! Thank u so much Rose!

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    February 6, 2019 at 09:14

    You’re welcome!
    Would you mind to rate our product: 
    https://prnt.sc/d256m6
    https://themeforest.net/downloads
    That would be much appreciated 🙂

    Regards

    Avatar: Tagbag
    Tagbag
    Participant
    February 6, 2019 at 09:30

    sure 😀

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    February 6, 2019 at 09:34

    I grateful to you for your kind words, really appreciated 🙂

    Regards

  • Viewing 10 results - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.