Simple theme, cart redirect function not working as expected

New Member
3 0 0

Hey there, with the Simple theme, there's an option in the theme cart settings to "Stay on current page when item is added to cart," but no matter what the selection is (on or off) the page always redirects to the cart. Any idea on why that might be broken?

 

My store is bikeoutco.myshopify.com and you can see the functionality in action by visiting this collection page: https://bikeoutco.myshopify.com/collections/bikeout-phoenixville

 

As I'm posting this, I have "Stay on Current Page" selected in the theme, so you'll see exactly what I mean.

 

Thank you so much in advance!

0 Likes
Shopify Partner
436 83 95

Hello 
The settings you are talking about is for product single page not for customized collection products add to cart button
Like i check your single product https://bikeoutco.myshopify.com/collections/bikeout-phoenixville/products/bikeout-phoenixville-t-shi... its working fine, add product to cart without redirecting to cart page.

And if you want to implement it same on your customization you have to follow theme code or you can check here https://bikeoutco.myshopify.com/collections/bikeout-phoenixville/products/bikeout-phoenixville-t-shi...

Want to modify or custom changes on store hire me.
My Email: guleriathakur43@gmail.com
Skype: navrocks1
If helpful then please Like and Accept Solution.
If you are happy and want to donate small Click here (Its my paypal)
0 Likes
New Member
3 0 0
Thank you so much, that's very helpful to understand! I'm wondering if
there's an easy way to take the behavior from the single product page and
apply it to my customized ollection page? The behavior on the single
product page, of clicking the icon to add to cart, and it switching to the
button language to "View cart," is exactly what I'm looking for on my
customized collection page. I tried a few times to copy/paste the code into
the product-grid-item, but it's not working as intended.

Thank you!
0 Likes
Shopify Partner
436 83 95

Change this 

<input type="submit" value="Add to cart" class="btn">

to this

<input type="button" product_id="{{ product.variants.first.id }}" value="Add to cart" class="add_to_cart btn" />

And add this js in same template or in your theme.js or related file

$(document).on('click','.add_to_cart',function(){
            var quantity = $(this).prev('#quantity').val();
            var id= $(this).attr('product_id');
            $.ajax({
                type: 'POST',
                url: '/cart/add.js',
                dataType: 'json',
                data: {id:id,quantity:quantity},
                success: function(){
                }
            });
        })

 

Want to modify or custom changes on store hire me.
My Email: guleriathakur43@gmail.com
Skype: navrocks1
If helpful then please Like and Accept Solution.
If you are happy and want to donate small Click here (Its my paypal)
0 Likes
New Member
3 0 0

Amazing, thank you! I added that to the product-grid-item, and the functionality does work in that it adds the items and doesn't redirect. That's amazing!

 
Just wondering, one thing that isn't happening is that after clicking add to cart, the button doesn't change to "view cart" and the cart itself in the top right doesn't get updated to show that items have been added to the cart.
 
The functionality does work, in that the items get added to the cart, but there's no visual change for the user to know that it's been added. I'm figuring maybe I didn't add the JS correctly - I added it to theme.js.liquid as instructed.
 
Is the js not functioning correctly (i.e., did I not add it correctly), or is there another thing I need to do in order to have those to elements (the button and the cart itself) update once you click "add to cart"?
 
thank you!
0 Likes
Shopify Partner
436 83 95

 

To add visual change, you have to write JS in success functions.

Thanks

Want to modify or custom changes on store hire me.
My Email: guleriathakur43@gmail.com
Skype: navrocks1
If helpful then please Like and Accept Solution.
If you are happy and want to donate small Click here (Its my paypal)
0 Likes