• Resolved Christiaan

    (@christiaan-grob)


    Hello,

    while working on my website I stuck on one thing i can not solve by my self.
    I want the shopping cart disabled for guest users. This is the code in my header:

    <li class="pk_option_item">
    						<?php if((sizeof($woocommerce->cart->cart_contents)) == 0):
        echo 'Shopping cart is empty!';
    ?>
    <?php else: ?>
      <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>"
           title="<?php _e('View your shopping cart', 'woothemes'); ?>">
    
            <?php echo sprintf(_n('%d product', '%d products',
                    $woocommerce->cart->cart_contents_count, 'woothemes'),
                    $woocommerce->cart->cart_contents_count);?> -
            <?php echo $woocommerce->cart->get_cart_total(); ?>
    
        </a>
    <?php endif; ?>
    						<span class="pk_option_item_divider"></span>
    					</li>
    <?php

    Anyone who can help me?

    Regards

    https://wordpress.org/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @christiaan, you can use this code instead:

    <li class="pk_option_item">
    <?php if(is_user_logged_in()): ?>
    <?php if((sizeof($woocommerce->cart->cart_contents)) == 0):
        echo 'Shopping cart is empty!';
    ?>
    <?php else: ?>
        <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>"
           title="<?php _e('View your shopping cart', 'woothemes'); ?>">
    
            <?php echo sprintf(_n('%d product', '%d products',
                    $woocommerce->cart->cart_contents_count, 'woothemes'),
                    $woocommerce->cart->cart_contents_count);?> -
            <?php echo $woocommerce->cart->get_cart_total(); ?>
    
        </a>
    <?php endif; ?>
    <?php endif; ?>
    <span class="pk_option_item_divider"></span>
    </li>
    Thread Starter Christiaan

    (@christiaan-grob)

    Super thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide shopping cart for guest…’ is closed to new replies.