How to show cart contents / total Woocommerce

Woocommerce-Theme-.png

You can Display the Cart contents and total in any of your template file. We mainly use in header.php file to show the cart.

Below is the code to display the icon:

cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - cart->get_cart_total(); ?>

With Ajax

// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)


	cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - cart->get_cart_total(); ?> 
	

Also you can try this:

cart->get_cart_contents_count();

// get cart total
$total = $woocommerce->cart->get_cart_total();

// get cart url
$cart_url = $woocommerce->cart->get_cart_url();

// if multiple products in cart
if($qty>1)
      echo ''.$qty.' products | '.$total.'';

// if single product in cart
if($qty==1)
      echo '1 product | '.$total.'';

?>

Visit us at Developergang to submit guest post related Technology + Write For Us + Guest Post