PoW8
July 16, 2024, 2:45pm
1
Hey, I used a code to change the default cart.
.header__icons a#cart-icon-bubble {
position: relative;
}
.header__icons a#cart-icon-bubble svg {
opacity: 0;
width: 60px !important;
}
.header__icons a#cart-icon-bubble:before {
position: relative;
content: ‘Cart’;
}
.header__icons a#cart-icon-bubble .cart-count-bubble {
left: auto;
right: 0px;
}
.header__icons a#cart-icon-bubble {
text-decoration: none;
}
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
what you can do is to
‘Online Store’ → Themes → Edit Code
Inside the assets folder locate the file ‘base.css’
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
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 -%}
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'] });
});
PoW8
July 17, 2024, 6:32pm
5
Unfortunately it didn’t seem to do anything.