×

 

Home Contact Us Payments SC Commerce SC Commerce Docs SC Commerce Snippets

Simply Computing

We make websites. Simple.

Display the cart contents and total in your template

To add a cart summary anywhere in your theme template use these few lines of code. The number of items in the cart and the total value will be displayed. This summary also acts as a link to the cart.

		/**
 * Display the cart contents and total in your template
 */

// Adds a line to your theme template that shows the number of items in the cart and the total value.
// The displayed summary is also a link to the cart.
// https://theme4press.com/20-useful-woocommerce-snippets-wordpress-themes/

<a href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
	
   View Raw Code ID: 93484