I have been searching for a solution for my problem from a while, but i couldn't manage to find one. So i recently added a discount app (HulkApps) that gives the customers a certain discount if they buy a certain number of products. For instance, if the customer added one product to the cart, the app tells them that they are one product away from 10% discount and then they can add another item so that they get the discount. The issue is that after they add the additional product the cart doesn't update so that they can see the 10% discount.The only way is to refresh the page manually, but am certain that not all people will do it. I need to make my cart page automatically reload once the quantity of a product has changed. I would appreciate your help.
That's the code that i have tried to use. I placed it in Assets --> cart-template.liquid
<script>
$('.qty-input').on('change', function(){
var prev = $(this).data('val');
var current = $(this).val();
setTimeout(function() {
if (prev != current){
location.reload();
}
}, 1);
});
</script>
Solved! Go to the solution
Hello,
Thank you for your question.
Please share your store URL, page URL and also password (if your store has one), I'll help you out to the best of my ability.
Kind regards,
Diego
Hello,
No problems, but I can only develop an appropriate solution by debugging the code - the theme used is irrelevant unfortunately.
I hope you manage to get this sorted out.
Kind regards,
Diego
yes, sure, that'd work!
@JordanM
1. In your Shopify Admin go to online store > themes > actions > edit code
2. In your theme.liquid file, find the </body> (press CTRL + F or command + F on Mac)
3. paste this code right above the </body> tag:
<script>
var firstChange = true;
function reloadCart(){
var target = document.querySelector(`[data-cart-subtotal]`);
if (!target)return
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (firstChange){
firstChange = false;
return;
} else{
setTimeout(window.location.reload(), 100);
}
});
});
var config = { attributes: true, childList: true, characterData: true };
observer.observe(target, config);
}
document.addEventListener("DOMContentLoaded", function() {
reloadCart();
});
</script>
Please let me know whether it works.
Kind regards,
Diego
try changing from 100 to 1000 in the code
User | Count |
---|---|
24 | |
20 | |
17 | |
16 | |
15 |