6

So...I just found out that the shortcodes for the login and registration pages are now removed from Woocommerce.... I know the forms are inside "My account" page, but I need a link in the menu to invite users to register or login, without having to explore the whole site first.

Is there a way to modify my theme's functions to achieve this (so I don't use another plugin)?

1 Answer 1

5

Using the [woocommerce_my_account] shortcode, a user will see their account details if they're logged in and if they're not logged in, they'll see a login and registration form.

Using the same page title "My Account" for these different users isn't ideal because a user that has never created an account won't naturally navigate to a "My Account" page in order to create an account.

A possible solution is to add the page that includes that shortcode twice to your navigation menu, name them "Login" and "My Account", and give them separate classes:

Login Nav Links

Then we can control the visibility of the navigation links based on if a user is logged in:

add_action('wp_head','jg_user_nav_visibility');
function jg_user_nav_visibility() {

    if ( is_user_logged_in() ) {
        $output="<style> .nav-login { display: none; } </style>";
    } else {
        $output="<style> .nav-account { display: none; } </style>";
    }

    echo $output;
}
5
  • Yes I am using that shortcode in my account page. I need a link in my menu to add the registration/login form too... People without an account will not click my account link, they will search for a registration link. Users that have an account might click it but they surely will look for a login page instead.. Is there a way to separate the forms from "my account" page? Commented Jul 3, 2015 at 15:41
  • Thanks. Tried adding the code to my functions but the 2 menu items are still displaying. The filter is not happening :/ Commented Jul 3, 2015 at 16:24
  • @CynthiaLara Make sure that you have the correct CSS classes applied to your separate menu items.
    – Jami Gibbs
    Commented Jul 3, 2015 at 16:28
  • I did. Will investigate further. Commented Jul 3, 2015 at 16:31
  • Ok so this did work well but somehow the inline style was not overriding the styles of display in style.css so I just added !important and it worked. Thanks :) Commented Jul 3, 2015 at 16:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.