• Hi,
    My site has a login feature for customers if they want to login. The problem I have is currently when a customer logs in there is not option and/or button to log out.

    I have added the below code to the Snippets plugin but the logout feature is not working.

    Could you please help me with this and let me know where I am going wrong?

    /**
    * Add a WooCommerce logout page shortcode button
    */

    // Shortcode Action hook

    add_shortcode( ‘wc_logout_shortcode’, ‘njengah_wc_logout_shortcode’ );

    // Callback

    function njengah_wc_logout_shortcode(){

    ob_start();
    // Check if user is logged in
    if (is_user_logged_in()){
    // Create the url variable
    $wc_shortcode_logout_url = site_url() . ‘/?customer-logout=true’;?>
    <button class=”wc_logout_shortcode_btn”>“>Log Out</button>
    <?php
    }

    return ob_get_clean();
    }

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    It doesn’t look like you’re attaching the link URL to the button in any way. I’d recommend switching out this line:

    <button class="wc_logout_shortcode_btn">Log Out</button>

    for this:

    <a href="<?php echo esc_url( $wc_shortcode_logout_url 
     );" class="wc_logout_shortcode_btn">Log Out</a>
Viewing 1 replies (of 1 total)

The topic ‘Logout Feature Code Snippet’ is closed to new replies.