Solved

ADD TO CART redirects to Product Page

GalingDyan
Tourist
7 0 6

Hi All, 


Been searching the forums and net for almost 2 hours and there are all kinds of solutions but it only solves 1 aspect of the problem. 


For starters: 

 

Im using the debut theme. 

I've added the ADD TO CART button to my collections. 


I've added the ajax code to my header, and product cart codes. 

I've solved the adding to cart from a product page not redirecting to the cart.


I have a featured collection on my main page with add to cart buttons below each item. 

I'm trying to not have it redirect to the product page when adding to cart on home page via the featured collection. 

How do I do that?

URL is: www.galingdyan.com 

Password: Test123

I'm at my wits end. 

 

Thanks in advance! 

Accepted Solution (1)
dmwwebartisan
Shopify Partner
12280 2546 3694

This is an accepted solution.

Hello @GalingDyan 

please add code Snippets/product-card-grid.liquid bottom of the file.

<form action="/cart/add" data-productid="{{product.id}}" method="post" class="product-form__item product-form__item--submit product-form__item--payment-button product-form__item--no-variants" id="AddToCartForm">
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
<input type="hidden" name="return_to" value="back" />
<input type="submit" value="Add to cart" id="addToCart" class="btn product-form__cart-submit btn--secondary-accent"/>
</form>

 

Hope this will work for you.


Thanks!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app

View solution in original post

Replies 10 (10)

diego_ezfy
Shopify Partner
2935 562 883

Hello,

Your store is password locked. Kindly share the password.

Thank you!

◦ Follow my blog & youtube for coding tutorials. Most questions in here are already answered there!
◦ Top #4 Shopify Expert, 24h reply. Click here to hire me.
Download copy/paste code snippets that can replace most apps.

GalingDyan
Tourist
7 0 6

Sorry! I just added the password I forgot it was locked since this is before launch. : )

dmwwebartisan
Shopify Partner
12280 2546 3694

Hey @GalingDyan 

Find this code In asset->theme.js->find "$.post(params)".

If your theme contains this then follow this:

add location.href="/cart";

So it looks like:

$.post(params)
.done(
function(item) {
this._hideErrorMessage();
this._setupCartPopup(item);
location.href="/cart";
}.bind(this)
)


Hope this will work for you.


Thanks!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app
GalingDyan
Tourist
7 0 6

@dmwwebartisan 


Thanks for the swift reply. 

 

GalingDyan_0-1597324824722.png

added but still takes me to the product page when adding to cart on the main page. 

 

See code above if I did it right. 🙂

 

dmwwebartisan
Shopify Partner
12280 2546 3694

Hey @GalingDyan,

Are you using ajaxsify?

Please share your button code.

Thanks! 

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app
GalingDyan
Tourist
7 0 6

Yup using ajaxify for the cart function. 


For the button code:

 

<form method="post" action="/cart/add"> <input type="hidden" name="id" value="{{ product.variants.first.id }}" /> <input min="1" type="number" id="quantity" name="quantity" value="1"/> <input type="submit" value="Add to cart" class="btn" /> </form>

 

added this at the end of product-card-grid,liquid

 

 

dmwwebartisan
Shopify Partner
12280 2546 3694

This is an accepted solution.

Hello @GalingDyan 

please add code Snippets/product-card-grid.liquid bottom of the file.

<form action="/cart/add" data-productid="{{product.id}}" method="post" class="product-form__item product-form__item--submit product-form__item--payment-button product-form__item--no-variants" id="AddToCartForm">
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
<input type="hidden" name="return_to" value="back" />
<input type="submit" value="Add to cart" id="addToCart" class="btn product-form__cart-submit btn--secondary-accent"/>
</form>

 

Hope this will work for you.


Thanks!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app
GalingDyan
Tourist
7 0 6

That work fantastically!

 

You are a legend!  


I hope this helps others as well.

HappyDogTribe
Tourist
4 0 1

Just wanted to say a massive THANK YOU! 

I'm using the Simple theme and had managed to get my add to cart button working on my collection pages but it kept redirecting to the cart. I know hardly anything about coding. Your response sorted the cart redirect out so customers can remain in the collection and keep shopping.

You're a total legend!

sonic2218
Visitor
1 0 0

This did not work for me. I am having the exact same issue, tried different codes but the button still takes me to the product page!

Any ideas?