MyListing Club

Hide Cart When Empty

Building better MyListing websites. One code snippet at a time.

Overview

The Hide Cart When Empty code snippet helps create a cleaner navigation area with fewer distractions for MyListing websites.

This applies to those that have toggled on the Show cart setting (Theme Tools > Theme Options > Header).

MyListing will show the shopping cart in the navigation area, regardless of whether someone has added anything to their cart.

Implementation

  1. Grab the code snippet.
  2. Follow the provided instructions.
  3. Save your changes.
				
					//// INSTRUCTIONS: 
//// Copy and paste the code snippet below into Appearance > Theme Editor > MyListing Child Theme > Theme Functions (functions.php), after '//happy coding'.

--------------------------- CODE SNIPPET IS BELOW THIS LINE --------------------------- 

// HIDE CART WHEN EMPTY
add_action( 'wp_footer', function() {
 
    if ( WC()->cart->get_cart_contents_count() < 1 ) :
    ?>
        <style type="text/css">
            .view-cart-contents:not(.user-cart-updated) {
                display: none !important;
            }
        </style>
    <?php
    endif;
} );