Personalized checkout and custom promotions with Shopify Scripts
So, I wanted a add a free product to my cartdrawer when the price reaches upto 50 dollars so i used chatGPT for this purpose and he gave me this code and said to paste it in the onSubmit function so i did but the function is not working.
I appreciate any help, as so far I have not found anything on this. I am a developer so I shoud be ok if pointed in the right direction.
Thanks!
onSubmit: function(evt) {
this.submitBtn.classList.add(classes.btnLoading);
if (config.requiresTerms) {
if (this.termsCheckbox.checked) {
// continue to checkout
} else {
alert(theme.strings.cartTermsConfirmation);
this.submitBtn.classList.remove(classes.btnLoading)
evt.preventDefault();
return false;
}
}
// Check if the total price is greater than or equal to $50
// Check if the total price is greater than or equal to $50 (or 13,700 Rupees)
var cartTotal = parseInt(this.subtotal.dataset.cartSubtotal);
if (cartTotal >= 5000) {
// Define the variant ID of the free product you want to add
var freeProductVariantId = '45824736788798';
// Add the free product to the cart
jQuery.ajax({
type: 'POST',
url: '/cart/add.js',
data: {
quantity: 1,
id: freeProductVariantId,
},
dataType: 'json',
success: function() {
// Refresh the cart drawer
jQuery.ajax({
type: 'GET',
url: '/cart',
dataType: 'html',
success: function(data) {
// Update the cart drawer content
jQuery('.cart-drawer__content').html(jQuery(data).find('.cart-drawer__content').html());
}
});
}
});
}
},
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024