Redirect User back to My Domain After payment success or fails

New Member
1 0 1

Is it Possible that the user will redirect back to my website after successful/failed Payment.

1 Like
Shopify Staff
Shopify Staff
53 0 2

Hi Jitenda,

Kevin here - a Shopify Guru :)

Yes this is possible to do by entering in some code into the Additional Scripts section of the Checkout area of your admin.

Such code would be:

<style type="text/css">body {display:none}</style>
<script type="text/javascript">
window.location.replace("https://yourstoresname.myshopify.com");
</script>

Whatever URL you enter there is where the customer will be redirected to after checkout.

I hope this helps!

Kevin | Shopify Guru

1 Like
New Member
1 0 0

Is there a way to apply the redirect to certain products (or collections or tags)

0 Likes
New Member
2 0 0

Does this work for failed transactions?

0 Likes
New Member
3 0 0

If you want to redirect people to a new page, check out a solution I found out at https://stackoverflow.com/a/59726180/7353382

 

If you want to provide custom code on the checkout page based on the product ID, try the following (user beware, code is ugly):

 

NOTE: This code is inserted into the Additional Scripts section of the Checkout area. To go there go to Settings > Checkout > scroll down to Additional Scripts.

 

<script>
  //the URLs to be redirected to
//replace the below with your own list {% assign redirect_1 = "https://www.URL-HERE.com/1" %} {% assign redirect_2 = "https://www.URL-HERE.com/2" %} {% assign redirect_3 = "https://www.URL-HERE.com/3" %} {% assign redirect_4 = "https://www.URL-HERE.com/4" %}
//replace the above with your own list //the products to check for
//replace the below with your own list {% assign product_1 = 1234567898765 %} {% assign product_2 = 1234567898764 %} {% assign product_3 = 1234567898763 %} {% assign product_4 = 1234567898762 %}
//replace the above with your own list //look at the items in the cart {% for line in checkout.line_items %} //grab the product id of the item
{% if line.product_id == product_1 %} Shopify.Checkout.OrderStatus.addContentBox(
//change the text in here to your liking '<p>You ordered product 1. <a href="{{ redirect_1 }}">Next, please visit this page.</a></p>' ) {% elsif line.product_id == product_2 %} Shopify.Checkout.OrderStatus.addContentBox(
//change the text in here to your liking '<p>You ordered product 2. <a href="{{ redirect_2 }}">Next, please visit this page.</a></p>' ) {% elsif line.product_id == product_3 %} Shopify.Checkout.OrderStatus.addContentBox(
//change the text in here to your liking '<p>You ordered product 3. <a href="{{ redirect_3 }}">Next, please visit this page.</a></p>' ) {% elsif line.product_id == product_4 %} Shopify.Checkout.OrderStatus.addContentBox(
//change the text in here to your liking '<p>You ordered product 4. <a href="{{ redirect_4 }}">Next, please visit this page.</a></p>' )

//add more blocks below here

//add more blocks above here
{% else %} Shopify.Checkout.OrderStatus.addContentBox( '<p>Thank you for your order</p>' ) {% endif %} {% endfor %} </script>

 

To make this work for you, do the following:

  1. Replace the list of `{% assign redirect_1 = "https://www.URL-HERE.com/1" %}` with the redirects you want to send people to.
  2. Replace the list of `{% assign product_1 = 1234567898765 %}` with your own products you want to provide redirects for.
  3. Change the text in the `<p>` tags as you see fit.
  4. Add more `{% elsif line.product_id == product_4 %}` blocks based on the size of your list.
0 Likes