[Resolved] Hide Cart Icon for users NOT logged in

Home Forums Support [Resolved] Hide Cart Icon for users NOT logged in

Home Forums Support Hide Cart Icon for users NOT logged in

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1195916
    Bailey

    I hadn’t been using the Woocommerce module for GeneratePress. I activated it and a cart appeared in the menu that wasn’t there before. In trying to remove it, I found this:

    https://generatepress.com/forums/topic/remove-shopping-cart-icon-from-home-page-header/

    Which solved the problem but now I’m wondering if I can have it but only for users that are logged in. I don’t see a setting for that.

    #1196163
    David
    Staff
    Customer Support

    Hi there,

    you can use the Woocommerce Options filter:

    https://docs.generatepress.com/article/option_generate_woocommerce_settings/

    TLDR: Try adding this PHP snippet to your site:

    add_filter( 'option_generate_woocommerce_settings','db_woo_nav_cart_logged_in' );
    function db_woo_nav_cart_logged_in( $options ) {
        if ( !is_user_logged_in() ) {
            $options['cart_menu_item'] = false;
        }
        return $options;
    }

    https://docs.generatepress.com/article/adding-php/

    #1196474
    Bailey

    Thanks for the TLDR update. Sorry it was long. Added PHP Snippet to theme editor. Cleared cache. Still showing for non-logged in users.

    #1196478
    David
    Staff
    Customer Support

    Just made a slight tweak to the code here – can you try that

    #1196483
    Bailey

    That fixed it! Thank you, David, for quick help that resolved the issues. Gotta love you guys at GeneratePress. That’s why I keep using it.

    #1196500
    David
    Staff
    Customer Support

    Awesome – glad to be of help and glad to hear that too!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.