Elementor & WooCommerce : Add Cart Item Count To Icon List

Elementor & WooCommerce : Add Cart Item Count To Icon List

Element.How also offers premium tutorials! Check them here:

Table of Contents

In this tutorial, I will teach you how to show the total count of items currently in the WooCommerce cart anywhere with Elementor.

We will be using the Elementor Icon List element, but really, this would work in a similar way with most elements.

This is what we are after:

Elementor & WooCommerce : Add Cart Item Count To Icon List 1

With this tutorial, you will have the total count on page load, and also it will be updated on any AJAX add to cart or remove from cart events.

Note: while this tutorial presents a way to make this work with Elementor, the same instructions will make this work for ALL WooCommerce websites, even if it's not an Elementor website.

First, add this WooCommerce Cart Total shortcode code snippet

The first thing you will do is add this code in a new PHP code snippet, either with the Code Snippets plugin, or in your child theme functions.php.

<script> 
/* Please login to get the code 
 * The code will be for the Elementor & WooCommerce : Add Cart Item Count To Icon List tutorial 
 * Found at this URL https://element.how/elementor-woocommerce-add-cart-item-count/ 
 */ 
</script>

Be certain to activate the code snippet after adding it.

Elementor & WooCommerce : Add Cart Item Count To Icon List 2

Then, go in your Elementor header template

Go in your Elementor header template (or anywhere else you want the WooCommerce cart count to show up), and add the icon list element.

For one of the items, choose the cart icon, and then in the text field enter this:

<script> 
/* Please login to get the code 
 * The code will be for the Elementor & WooCommerce : Add Cart Item Count To Icon List tutorial 
 * Found at this URL https://element.how/elementor-woocommerce-add-cart-item-count/ 
 */ 
</script>

Elementor & WooCommerce : Add Cart Item Count To Icon List 3

 

Getting in the styling

Let's style it better, otherwise it looks like this:

Elementor & WooCommerce : Add Cart Item Count To Icon List 4

Let's add this CSS under Advanced > Custom CSS for the icon list element:

<script> 
/* Please login to get the code 
 * The code will be for the Elementor & WooCommerce : Add Cart Item Count To Icon List tutorial 
 * Found at this URL https://element.how/elementor-woocommerce-add-cart-item-count/ 
 */ 
</script>

You will see this part, two times in the CSS:

:nth-child(3)

Adjust both so that it matches your own icon.

For example, if your cart icon is the first in your icon list, change to :nth-child(1) instead of :nth-child(3).

The rest of the CSS, adjust as needed to position and style your count.

If you aren't using Elementor

Everything still works. You will need this html where you want the count to show up:

<script> 
/* Please login to get the code 
 * The code will be for the Elementor & WooCommerce : Add Cart Item Count To Icon List tutorial 
 * Found at this URL https://element.how/elementor-woocommerce-add-cart-item-count/ 
 */ 
</script>

And then add this CSS to your project:

<script> 
/* Please login to get the code 
 * The code will be for the Elementor & WooCommerce : Add Cart Item Count To Icon List tutorial 
 * Found at this URL https://element.how/elementor-woocommerce-add-cart-item-count/ 
 */ 
</script>

A parent element will need to have position:relative; so that the count is positioned in relation to that parent element.

Finally, enjoy your Elementor icon with a live count of the WooCommerce cart items!

I hope you have enjoyed this tutorial!

Cheers!

Element.how also provides premium tutorials showing awesome advanced designs, check them out here.

Looking for something else? Search across 2927 Elements right here:

Checkout the Elementor Addon Finder directly

4 Responses

Leave a Reply