Redirect to custom page after adding to cart

Highlighted
New Member
2 0 0

I am using the DEBUT Theme. On the product page, when someone clicks "ADD TO CART" button, how can I redirect to a different page after adding the item to cart? And on that custom page, redirect them back to the cart after clicking a button on that page "CONTINUE TO CART"?

I have an idea on how to redirect to the custom page, editing the product-template.liquid, but how do I get it to add to the cart at the same time.

I see a similar question was answered here but not sure what's the Drawer Cart.

0 Likes
Highlighted
New Member
2 0 0

The solution that @tim provided in that link worked for adding to the cart and redirecting to my custom page...I just added it to the bottom section of the form.

<input type="hidden" name="return_to" value="/collections/all" />

The only thing left of figuring out how to redirect back to he cart when "CONTINUE TO CART" is clicked.

0 Likes
Highlighted
Shopify Expert
2684 67 827

Debut has no Drawer cart (unless you've an App for this), so you can use that suggestion.

Drawer cart is an option in some themes to add to cart without leaving the current page and the cart element kinda slides out (therefore drawer) from the side.

To add a a button to go to cart, you may add this HTML code:

<a href="/cart" class="btn btn--secondary">Continue to cart</a>

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
I am away till Feb-15.
1 Like
Highlighted
Shopify Partner
125 0 15

You would need to use the ajax call to add to the cart, and then on the success handler redirect to the custom page. and then set the link on the button as a link to take them to the cart.

Here is the java script I use to do something similiar  below is the code I use I replaced the success handler with the redirect, you would just need to replace the "custom page url" instances with the url you want to send them to, and replace the button id with the appropriate query to get the button that your users will click, and work backwords to get the variant id if none is selected, aka when the product page is first opened. I am using the supply theme so the variant from the url paramater may not work for you but I think it should.

ypu also will need to change the add to cart button from type=“submit” to type=“button”

function parseQueryString() {

    var str = window.location.search;
    var objURL = {};

    str.replace(
        new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
        function( $0, $1, $2, $3 ){
            objURL[ $1 ] = $3;
        }
    );
    return objURL;
};


function addToCartKeepShopping() {
	var addToCartObject = {};
  	var params = parseQueryString();
  	if(params["variant"]){
  		addToCartObject["id"]=parseInt(params["variant"]) 
    } else {
    	addToCartObject["id"]=parseInt($("#productSelect-product-template")[0].children[0].value) 
    }
	addToCartObject["quantity"]= parseInt($("#quantity")[0].value)
    $('#addToCart-product-template-keepshopping').blur();
  	document.getElementById('loadingwrapper').style.display = "block";
	$.ajax({
		url: '/cart/add.js',
		type: 'POST',
        data: addToCartObject,
        success: function(result) {
			window.location.href = "custom page url"
        },
        error: function(jqxhr, status, exception) {
			if (jqxhr.status == 200) {
				window.location.href = "custom page url"
			}
		}
	});
}

 

1 Like
New Member
2 0 0

I'd like to do something similar with Prestige - I'd like to:

 

1. change the add to cart button name (I can see how to change this in languages, but I only want to change the name of some of the add to cart buttons, not all)

2. redirect the button for specific products to a specific page on my shopify site when it's clicked (adding the item to cart with the same click)

 

(I have the drawer shopping cart set up to allow for the mega menu).

 

I hope you can help! :) 

0 Likes
Highlighted
Shopify Partner
3 0 0
<input type="hidden" name="return_to" value="/collections/all" />

The code above work fine but I need to create two buttons:
1) add to cart with no redirect
2) add to cart and redirect to custom page

0 Likes
Highlighted
Excursionist
19 0 2

Sorry, what do you mean? Are there 2 different "Add to cart" buttons on your site that behave differently?

0 Likes