Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sally165/bc2ce12e65f60d750cc33a7233388bf5 to your computer and use it in GitHub Desktop.
Save Sally165/bc2ce12e65f60d750cc33a7233388bf5 to your computer and use it in GitHub Desktop.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
try {
setTimeout(function () {
window.__pagefly_helper_store__ &&
window.__pagefly_helper_store__.subscribe(function (res) {
$.getJSON('/cart.json').then(cart => {
fetch('/cart?view=item').then(response => response.text())
.then(text => {
const sectionInnerHTML = new DOMParser().parseFromString(text, 'text/html');
const cartFormInnerHTML = sectionInnerHTML.getElementById('CartDrawer').innerHTML;
const totalPrice=sectionInnerHTML.querySelector('#CartDrawer .totals__subtotal-value').innerHTML;
$('#CartDrawer').html(cartFormInnerHTML)
$('cart-drawer').removeClass('is-empty')
$('cart-drawer-items').removeClass('is-empty')
if($('#cart-icon-bubble .cart-count-bubble').length===0){
const cartNumber=document.createElement('div')
cartNumber.className='cart-count-bubble'
cartNumber.innerHTML=`
<span aria-hidden="true">${cart.item_count}</span>
<span class="visually-hidden">${cart.item_count} items</span>
`
$('#cart-icon-bubble').append(cartNumber)
}else{
$('.cart-count-bubble span[aria-hidden="true"]').each((_,count)=>$(count).text(cart.item_count))
}
$('#cart-icon-bubble')[0].click()
$('#CartDrawer-Overlay').on('click',()=>{
$('cart-drawer').removeClass('active')
$('body').removeClass('overflow-hidden')
})
})
});
});
}, 2500);
} catch (e) {
console.warn(e);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment