Skip to content

Instantly share code, notes, and snippets.

@Sally165
Created April 21, 2023 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sally165/f8fab62646848f85781a8070bcc6a2ce to your computer and use it in GitHub Desktop.
Save Sally165/f8fab62646848f85781a8070bcc6a2ce to your computer and use it in GitHub Desktop.
<!-- PageFly cart helper custom. Please DONT DELETE -->
<script>
window.addEventListener('load', () => {
var pfATCs = $('#__pf').find('[data-pf-type="ProductATC"]');
pfATCs.click(e => {
var checkoutAction = e.currentTarget.getAttribute('data-checkout');
if (checkoutAction === 'same') {
window.__pagefly_helper_store__ && window.__pagefly_helper_store__.subscribe(function() {
$.getJSON('/cart.json').then(cart => {
var count = cart.item_count
$('.cart--external--total-items').text(count);
if (count > 0) {
$('.cart--external--total-items').css('display', 'inline-block');
return $('.cart--external--total-items').parent().show();
} else {
$('.cart--external--total-items').not('.header--mobile-cart-count').hide();
return $('.cart--external--total-items').not('.header--mobile-cart-count').parent().hide();
}
});
$.ajax({
url: theme.classes.FrameworkCart.prototype.getAjaxUrl(),
type: "GET",
dataType: "html"
}).done(function(data) {
var cart_html;
cart_html = $($.parseHTML(data));
$('.cart--root').attr('data-has-items', true)
$('.cart--root').find('.cart--form').replaceWith(cart_html.find('.cart--form'));
});
})
}
})
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment