Archived topic
Hide Cart Icon for users NOT logged in
5 replies · Started by Bailey on March 15, 2020
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.
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;
}
Thanks for the TLDR update. Sorry it was long. Added PHP Snippet to theme editor. Cleared cache. Still showing for non-logged in users.
Just made a slight tweak to the code here - can you try that
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.
Awesome - glad to be of help and glad to hear that too!