Cart Counter: No Bubble + Align + Display 0

Hey, I used a code to change the default cart.

  1. .header__icons a#cart-icon-bubble {

  2. position: relative;

  3. }

  4. .header__icons a#cart-icon-bubble svg {

  5. opacity: 0;

  6. width: 60px !important;

  7. }

  8. .header__icons a#cart-icon-bubble:before {

  9. position: relative;

  10. content: ‘Cart’;

  11. }

  12. .header__icons a#cart-icon-bubble .cart-count-bubble {

  13. left: auto;

  14. right: 0px;

  15. }

  16. .header__icons a#cart-icon-bubble {

  17. text-decoration: none;

  18. }

Could anyone possibly help me remove the cart counter bubble, align the counter on the same horizontal line as my new cart and make the cart display 0 when it is empty?

pw: teunti

Thanks in advance for any time given.

If you want the cart bubble to be vertically aligned with the cart and look like this

cart.PNG

what you can do is to

  1. ‘Online Store’ → Themes → Edit Code

  2. Inside the assets folder locate the file ‘base.css’

  3. At the bottom of the file at this code

.header__icons a#cart-icon-bubble .cart-count-bubble{
   top: 50%;
   transform: translateY(-50%);
}

If you want to show 0 inside the bubble if the cart is empty you need to change the liquid code of the header.

1.Go to ‘Online Store’ → Themes → Edit Code

  1. Inside the sections folder locate the file ‘header.liquid’ or similar. You need to find the element with class name ‘header__icon–cart’ which looks something like this

        {%- liquid
          if cart == empty
            render 'icon-cart-empty'
          else
            render 'icon-cart'
          endif
        -%}
        {{ 'templates.cart.cart' | t }}
        {%- if cart != empty -%}
          

            {%- if cart.item_count < 100 -%}
              {{ cart.item_count }}
            {%- endif -%}
            {{ 'sections.header.cart_count' | t: count: cart.item_count }}
          

        {%- endif -%}
      
  1. Remove the if statement ‘{%- if cart != empty -%}’ so it shows the bubble even if the cart is empty. It should look like this

        {%- liquid
          if cart == empty
            render 'icon-cart-empty'
          else
            render 'icon-cart'
          endif
        -%}
        {{ 'templates.cart.cart' | t }}
          

            {%- if cart.item_count < 100 -%}
              {{ cart.item_count }}
            {%- endif -%}
            {{ 'sections.header.cart_count' | t: count: cart.item_count }}
          

      

Hi @PoW8 ,

This is code updated. Please replace it


Hi @PoW8 ,

If you want to make the cart display 0 when it is empty? You need to insert script code before the tag in theme.liquid file

document.addEventListener('DOMContentLoaded', function() {
  const cartIconBubble = document.querySelector('#cart-icon-bubble');
  const svgIcon = cartIconBubble.querySelector('svg');
  const h = document.querySelector('.section-header');

  function checkSvgIconClass() {
    let cartCountBubbleEmpty = cartIconBubble.querySelector('.cart-count-bubble-empty');

    if (svgIcon?.classList.contains('icon-cart-empty')) {
      if (!cartCountBubbleEmpty) {
        cartCountBubbleEmpty = document.createElement('div');
        cartCountBubbleEmpty.className = 'cart-count-bubble';
        cartCountBubbleEmpty.innerHTML = '00 item';
        cartIconBubble.appendChild(cartCountBubbleEmpty);
      } else {
        cartCountBubbleEmpty.style.display = 'block';
      }
    } else {
      if (cartCountBubbleEmpty) {
        cartCountBubbleEmpty.style.display = 'none';
      }
    }
  }

  checkSvgIconClass();

  const observer = new MutationObserver(() => {
    checkSvgIconClass();
  });

  observer.observe(h, { attributes: true, attributeFilter: ['class'] });
});

Unfortunately it didn’t seem to do anything.