Changing "Log in" Button to "My Account" after use logs in

Hi guys,

I’m making an online shop using X Pro and WooCommerce, I’d like to have a “Log in” button in my header. When a customer logs in I’d like that button to change to “My account” which would be the Woocommerce account page.

Is this possible without needing to mess around with child themes?

Thanks!
Jon

Hi Jon,

To add that button, you will need to install and activate a child theme.

Then add the code below in your child theme’s functions.php file.

function add_btn() {
    ?>
    <span class="my-btn">
    <?php
 if ( is_user_logged_in() ) { ?>
     <a class="x-btn x-btn-flat x-btn-square x-btn-regular" href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a>
 <?php } 
 else { ?>
     <a class="x-btn x-btn-flat x-btn-square x-btn-regular" href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login','woothemes'); ?>"><?php _e('Login','woothemes'); ?></a>
 <?php } ?>
     </span>
 <?php
 
}
add_action( 'x_after_view_global__brand', 'add_btn', 10 );

I am not exactly sure where in the header you would like the button to appear, that code will add it after your logo.

Please let us know where you would like it to appear so we can adjust the code.

Thanks

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