Staying on product page after adding item to cart (Narrative)

Highlighted
New Member
1 0 0

Hello, I am having trouble getting this to work. I followed the guide here to no avail:

https://help.shopify.com/en/themes/customization/products/add-to-cart/stay-on-product-page-when-item...

 

I know using the cart drawer instead is an option, but I would rather use the cart page.

Has anyone run into problems following this guide, or has done this for Narrative theme?

Thanks

0 Likes
Highlighted
Shopify Expert
3915 559 940

Hi,

You can set like following to add product cart without page reload.

$(document).on('click','.AddToCart',function(){
    var quantity = quantity here..;
    var  ids = variants id here..;
    $.ajax({
      type: 'POST', 
      url: '/cart/add.js',
      dataType: 'json', 
      data: {id:id,quantity:quantity},
      success: function(){
             
      }
   });
})

Note: You need to add  AddToCart class in your existing button and change input type button from submit.

-Also you need to change code for variants and quantity by jquery base on your theme.

Let me know if you need help.

Want to modify or custom changes on store hire me.
Want to give Gift for time? its my Paypal too.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com Or WhatsApp
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes
Highlighted
Excursionist
18 0 2

Hi Jasoliya

I have been trying to make all my collection pages stay on page when adding a product to cart. I  have gotten this far on my button but it redirects back to page instead of holding at page in  view cart button as such below on my product page. Any help appreciated. 

collection page button.JPG

view cart button.JPG

 

 This is my latest coding but secondary button does not activate. It moves on to shopping cart after removing  <input type="hidden" name="return_to" value="back" /> 

</a>
<form method="submit" action="/cart/add">
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
<input class="product-form__quantity-input" type="number" id="Quantity-product-template" name="quantity" value="1" min="1" pattern="[0-9]*" style="padding-left: 105.925px; opacity: 3;">
<button class="btn btn--to-secondary btn--full product__add-to-cart-button shopify-payment-btn btn--secondary" data-cart-submit="" type="submit" name="add" aria-label="Add to Cart">
<span class="primary-text" aria-hidden="false" data-cart-primary-submit-text="">
Quick Add
</span>
<span class="secondary-text" aria-hidden="true" data-cart-secondary-submit-text="">View cart</span>
</button>



</form>

</div>

 

0 Likes
Highlighted
Shopify Expert
3915 559 940

If you take button type="submit" then it must redirect page.

you have to add Ajax code and then change type="submit" to type="button" 

Want to modify or custom changes on store hire me.
Want to give Gift for time? its my Paypal too.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com Or WhatsApp
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes