Personalized checkout and custom promotions with Shopify Scripts
I am trying to execute some code when the Shopify checkout form is submitted but it is not firing.
$(document).ready(function () { $(document).on('submit', '.ajax-cart__cart-form', function(e) { e.preventDefault(); // Prevent the default form submission alert('testing'); if ($('#add-product-checkbox').is(':checked')) { // Use Shopify AJAX API to add the product to the cart $.ajax({ type: 'POST', url: '/cart/add.js', data: { quantity: 1, // Adjust the quantity as needed id: 12345 // Variant ID of the product to add }, dataType: 'json', success: function(response) { // Redirect the user to the checkout page window.location.href = '/checkout'; }, error: function(jqXHR, textStatus, errorThrown) { console.log('Error adding the product to the cart'); console.log(textStatus); } }); } else { // If the checkbox is not checked, proceed to the regular checkout window.location.href = '/checkout'; } }); });
My classes are correct and other jQuery code fires within the document.ready block but this doesn't get touched.
Thanks!
I'm guessing this is not possible due to the lack of a response?
Can please you provide a bit more context what you are trying to achieve? We assume you are on Shopify Plus?
Cheers.
WhiteWater Web
On my cart page, I added a checkbox so the user can add a product to the cart. I want this product to be added if the checkbox is checked but only when the user submits the Checkout form. I have added the code above but nothing happens when the Checkout form is submitted.
Yes, I am on ShopifyPlus.
Mind if we take a look at the site, to see an example of what you have done so far?
Cheers.
WhiteWater Web
Removed.
Is this, "Would you like to have your stone crabs claws professionally cracked ($1.50 per pound)" a product in the back end?
PM us if you want too.
Cheers.
PM Sent, thanks.
I am still in search of help with this issue and would appreciate assistance.
*bump* anyone with any ideas or pointers for this?
The year-end shopping spree is around the corner! Is your online store ready for the ...
By JasonH Nov 10, 2024We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024