I created some custom links to add new products to the cart using the "href" attribute, my code looks like this.
<a class="line1" id="btn2" href="?add-to-cart=5207">Example</a>
But I didn't like the fact that every time I added a product it refreshed the whole page so I started looking for a different approach, and I found a way to do it with some jQuery code, It's adding the product but as the page is not reloading the cart icon doesn't update until I reload the page manually. The code looks like this.
jQuery(document).ready(function( $ ){
$('#buy').click(function(e) {
console.log('Working!!')
e.preventDefault();
prodId = $(this).attr("data-prod-id");
addToCart(prodId);
return false;
});
function addToCart(p_id) {
$.get('?add-to-cart=' + p_id, function() {
// call back
});
}
});
Is there a way to add some code to my jQuery function in order to update only the cart icon so that it shows the new products added?