Shopify themes, liquid, logos, and UX
I created an Add to Cart button. After the goods are added successfully, there is no item in the shopping cart and it needs to be refreshed. Besides, the sidebar-Cart will not be expanded
this is code:
<script type="text/javascript">
$(document).ready(function(){
$("#section-{{ section.id }} input[type='radio']").each(function(){
$(this).click(function(){
var data=$(this).attr("data-variant")
var imgurl=$(this).attr("data-image-url")
var url = imgurl.replace(/_{width}x/ig, '')
$(this).parents(".ProductItem__Wrapper").next().attr("id",data)
$(this).parents(".ProductItem__Info").prev().children().children().eq(1).attr("data-srcset",url)
$(this).parents(".ProductItem__Info").prev().children().children().eq(1).attr("srcset",url)
})
})
function addItemToCart(variant_id, qty) {
var data = {
"id": variant_id,
"quantity": qty
}
$.ajax({
type: 'POST',
url: '/cart/add.js',
data: data,
dataType: 'json',
success:function() {
location.reload();
alert("Thank You! The Product Was added to the Cart Successfully.");
}
});
}
$('#section-{{ section.id }} .yyz-button-btn').each(function(){
$(this).click(function(){
addItemToCart($(this).attr("id"),$(this).attr("quantity"));
})
})
});
</script>
User | RANK |
---|---|
215 | |
145 | |
66 | |
46 | |
45 |
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023