• Resolved teeboy4real

    (@teeboy4real)


    Hello,

    How can I hide the menu cart for logged out users, only logged in users can view the menu cart.

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    You can do this with CSS:

    
    :not(.logged-in) .wpmenucartli {
        display: none;
    }
    

    You can add this in the theme customizer (“Additional CSS”) or in style.css if you work with a child theme.

    Hope that helps!

    Thread Starter teeboy4real

    (@teeboy4real)

    Thanks but I would really prefer this being done using a code in functions.php file than using CSS (this is more of a cosmetic approach)

    Plugin Contributor Ewout

    (@pomegranate)

    It shouldn’t make a big difference in practice, but you can clear the contents with a filter:

    
    add_filter('wpmenucart_menu_item_a_content', 'wpmenucart_only_logged_in', 10, 4)
    function wpmenucart_only_logged_in( $link_content, $menu_item_icon, $cart_contents, $item_data ) {
    	if (!is_user_logged_in())) {
    		$link_content = '';
    	}
    	return $link_content;
    }
    
    Thread Starter teeboy4real

    (@teeboy4real)

    Hello,

    I received a syntax error, unexpected T_FUNCTION on this line function wpmenucart_only_logged_in( $link_content, $menu_item_icon, $cart_contents, $item_data ) {
    if (!is_user_logged_in())) {

    I am using php version 7.2

    Thanks

    Plugin Contributor Ewout

    (@pomegranate)

    apologies, there was a typo, try this:

    
    add_filter('wpmenucart_menu_item_a_content', 'wpmenucart_only_logged_in', 10, 4);
    function wpmenucart_only_logged_in( $link_content, $menu_item_icon, $cart_contents, $item_data ) {
    	if (!is_user_logged_in()) {
    		$link_content = '';
    	}
    	return $link_content;
    }
    
    Thread Starter teeboy4real

    (@teeboy4real)

    Thank you very much the code worked perfectly

    Plugin Contributor Ewout

    (@pomegranate)

    Glad to hear that @teeboy4real! If you can spare a minute, I’d appreciate a plugin review here: https://www.ads-software.com/support/plugin/woocommerce-menu-bar-cart/reviews/#new-post

    Thanks in advance and have a fantastic weekend!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hide menu cart for logged out users’ is closed to new replies.