Okay
  Public Ticket #2815613
Logout button
Closed

Comments

  • Ranjay Sikka started the conversation

    Hi 

    I wanted to put a logout button in my header as well. So when a user is logged into my website they can directly log out from the header instead of going to my account page and logging out from there.


    Is it possible to do this.


    Thank you.

  •  2,217
    WebWizards replied

    Hi Ranjay,

    Thank you for purchasing our plugin,


    B2BKing doesn't have such a functionality - we feel that this is a general WooCommerce function, while our plugin aims to do only things that are very specifically B2B/Wholesale only.


    If you are comfortable working with code / code snippets, you can add a logout button anywhere in the site, by using a hook and adding the following snippet:

    <a href="<?php echo esc_url(wc_logout_url()); ?>">
        <button id="wp-submit" type="submit" value="Login" name="wp-submit" class="btn btn-lg btn-primary btn-block">Log out</button>
    </a>
    



    For example, if you use the Storefront theme, and want to add the button before the header, you can use the "storefront_before_header" hook


    The final code is:

    add_action('storefront_before_header', function(){
        if (is_user_logged_in()){
            ?>
            <a href="<?php echo esc_url(wc_logout_url()); ?>">
                 <button id="wp-submit" type="submit" value="Login" name="wp-submit" class="btn btn-lg btn-primary btn-block">Log out</button>
             </a>
            <?php
        }
    });


    Kind regards,

    Stefan