How to Target Visitors Based on How Many Items are in Their Cart

So, you want to target customers that have something in their cart (or nothing in their cart). This is a good use case for Ecommerce customers that want to offer a little incentive when they have added something to their cart and are about to leave.

This is going to vary from website to website. So, please email us and we can write this custom JS in your account for you.

Essentially you want to look in your HTML/CSS to see what class is displayed to show the item number. Below is the custom JS where the class is “shopping-cart” and the number of items is displayed in a badge. This custom JS will live in the “After Document Ready” section of your Custom JS.

//Badge Targeting
var badgeVal = '';
if (JQUERY_DIGIOH('#shopping-cart').length) {
    badgeVal = JQUERY_DIGIOH('#shopping-cart').find('span.badge').eq(0).html();
}

if (!badgeVal || badgeVal === '' || badgeVal === '0') {
    //They have zero items in their cart
    JQUERY_DIGIOH('body').append('<div id="digioh-cart-zero"></div>');
    DIGIOH_CUSTOM_JS.log('digioh-cart-zero');
} else {
    //They have one or more items in their cart
    JQUERY_DIGIOH('body').append('<div id="digioh-cart-one-or-more"></div>');
    DIGIOH_CUSTOM_JS.log('digioh-cart-one-or-more');
}

You now have 2 new rules available to you:

#digioh-cart-zero (Target people with nothing in their cart)

— or —

#digioh-cart-one-or-more (Target people with 1 or more item in their cart)

You would use the HTML Exists JQuery rule for this.