Header My Account with username - by guilherme

This topic has 10 replies, 3 voices, and was last updated 7 years, 3 months ago ago by Olga Barlow

  • 9 Answers
    Avatar: 8theme
    8theme
    Support staff
    November 28, 2016 at 09:11

    Hello,

    “My account” link text can be changed from the ‘xstore/framework/theme-functions.php’ file. Function name containing this text is etheme_get_links

    Regards

    Avatar: guilherme
    guilherme
    Participant
    November 28, 2016 at 11:40

    Can I put php condition to show username???

    Avatar: 8theme
    8theme
    Support staff
    November 28, 2016 at 14:54

    Yes, you can put the username there as well. Just need to customize the PHP function etheme_get_links

    Avatar: guilherme
    guilherme
    Participant
    November 28, 2016 at 16:58

    Do you have an example to do this? I don´t have enought expertise to do this 🙁

    Avatar: 8theme
    8theme
    Support staff
    November 29, 2016 at 08:42

    Try to replace this function with the following code

        function etheme_get_links($args) {
            extract(shortcode_atts(array(
                'short'  => false,
                'popups'  => true,
            ), $args));
            $links = array();
    
            $reg_id = etheme_tpl2id('et-registration.php');
    
            $login_link = wp_login_url( get_permalink() );
    
            if( class_exists('WooCommerce')) {
                $login_link = get_permalink( get_option('woocommerce_myaccount_page_id') );
            }
    
            if(etheme_get_option('promo_popup')) {
                $links['popup'] = array(
                    'class' => 'popup_link',
                    'link_class' => 'etheme-popup',
                    'href' => '#etheme-popup',
                    'title' => etheme_get_option('promo-link-text'),
                );
                if(!etheme_get_option('promo_link')) {
                    $links['popup']['class'] .= ' hidden';
                }
                if(etheme_get_option('promo_auto_open')) {
                    $links['popup']['link_class'] .= ' open-click';
                }
            }
    
            if( etheme_get_option('top_links') ) {
                if ( is_user_logged_in() ) {
                    $user=wp_get_current_user();
                    $name=$user->display_name; // or user_login , user_firstname, user_lastname
                    if( class_exists('WooCommerce')) {
                        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 = '<ul>';
                            $permalink = wc_get_page_permalink( 'myaccount' );
    
                            foreach ( wc_get_account_menu_items() as $endpoint => $label ) {
                                $url = ( $endpoint != 'dashboard' ) ? wc_get_endpoint_url( $endpoint, '', $permalink ) : $permalink ;
                                $submenu .= '<li class="' . wc_get_account_menu_item_classes( $endpoint ) . '"><a href="' . esc_url( $url ) . '">' . esc_html( $label ) . '</a></li>';
                            }
    
                            $submenu .= '</ul>';
                        }
    
                        $links['my-account'] = array(
                            'class' => 'my-account-link',
                            'link_class' => '',
                            'href' => get_permalink( get_option('woocommerce_myaccount_page_id') ),
                            'title' => esc_html__( 'Welcome, ', 'xstore' ) . $name,
                            'submenu' => $submenu
                        );
    
                    }
                    // $links['logout'] = array(
                    //     'class' => 'logout-link',
                    //     'link_class' => '',
                    //     'href' => wp_logout_url(home_url()),
                    //     'title' => esc_html__( 'Logout', 'xstore' )
                    // );
                } else {
    
                    $login_text = ($short) ? esc_html__( 'Sign In', 'xstore' ): esc_html__( 'Sign In or Create an account', 'xstore' );
    
                    $links['login'] = array(
                        'class' => 'login-link',
                        'link_class' => '',
                        'href' => $login_link,
                        'title' => $login_text
                    );
    
                    if(!empty($reg_id)) {
                        $links['register'] = array(
                            'class' => 'register-link',
                            'link_class' => '',
                            'href' => get_permalink($reg_id),
                            'title' => esc_html__( 'Register', 'xstore' )
                        );
                    }
    
                }
            }
    
            return apply_filters('etheme_get_links', $links);
        }

    Regards

    Avatar: guilherme
    guilherme
    Participant
    November 29, 2016 at 11:17

    Wooooowwwww. awesome..THANKS A LOT!

    Avatar: 8theme
    8theme
    Support staff
    November 29, 2016 at 14:46

    You are welcome!

    I would be very appreciated if you leave 5-stars rating for our theme on TF https://themeforest.net/downloads and good comment about support.
    Thank you!

    Regards

    Avatar: guilherme
    guilherme
    Participant
    December 8, 2016 at 16:55

    I made this change in xstore/framework/theme-functions.php to show username in header, If I update theme I losst all configs right? Can I put this theme-functions.php in child theme and works fine or I need to crete a folder called framework and put there the php file?

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    December 8, 2016 at 18:04

    Hello,

    You will lose all the changes if you made them in the parent theme. Do all the changes in child theme.
    If you want to change any function copy-paste this function into functions.php of child theme and do the changes there, you don’t need to copy all the content of theme-functions.php, just necessary function. Then it will work.

    More details how to use child theme you can find here https://codex.wordpress.org/Child_Themes

    Regards

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

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

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