Redirect user to a page after payment in shopify

New Member
3 0 1

I send user to shopify with certain product number and quantity, which is being populated with price on shopify where user can make a payment,

Now i want the user to be redirected to a certian page in my website, after successful payment,

I created webhook order payemnt and given the url of the page to be redirected after payment, but it is not working

Please suggest

1 Like
Shopify Staff
Shopify Staff
149 0 7

Hello!

Jesse from the Guru Team here.

While this would be considered a bit of hack you can achieve this with a bit of JS:

<script> window.location =" http://YOURURLHERE.COM "; </script>

Replace yoururlhere.com with your desired page, and place the code in the additional content and scripts section found in the Checkout section of the admin.

http://docs.shopify.com/support/configuration/store-customization/legacy-checkout/how-do-i-customize...

Feel free to reach out at any time if you have any other questions.

http://docs.shopify.com/support

support@shopify.com

2 Likes
New Member
1 0 1

Jesse, THANKS SO MUCH. This was exactly what I was struggling to accomplish: to redirect users after a purchase.

So I pasted the code as you said, however it applies to ALL my products.

 

<script> window.location ="https://myurl.com/page"; </script>

 

Is there a way of discriminating? I would like that code to run for product B, but NOT for product A.

 

Thanks!!

1 Like
New Member
3 0 0

BUMP

0 Likes

Here's your full code:

 

 

try {
   let redirect_url = 'https://example-page-link.com/your-page';
   let redirect_prod_ids = [1651456314292, 1651496847236];

   let order_line_items = Shopify.checkout.line_items;
   for( var i=0; i<order_line_items.length; i++ ){
      if( redirect_prod_ids.includes( order_line_items[i].product_id ) ){
         window.top.location.href = redirect_url;
      }
   }
}catch(err){
   //if errors happen in the above code, do nothing
} 

 

 

redirect_url = the URL where you want to send the users;
redirect_prod_ids = put one or multiple product IDs separated by a comma (,) for which you want to redirect the users (works even if user has purchased multiple items on that particular order). You can get the product ID from your product's admin editor like so: 

You're welcome.

11 years of web development experience and recently into Shopify Apps.
1 Like
New Member
1 0 0

Hello — could this be quantified by some sort of an "if/then" statement?

I have a collection where if someone purchases something from that collection, I'd like them to be redirected to a specific page to fill out a form with more information. 

 

Could I put the collection in there? Or should I list every individual product like Altin suggested above?

0 Likes
Shopify Partner
17 0 3

Thank you Altin.

0 Likes
New Member
1 0 0

Where does the code go for this 

 

 

0 Likes
Shopify Partner
17 0 3

The code goes into Settings > Checkout > Order processing > Additional scripts

Also, don't forget to wrap the code between <script></script> tags.

1 Like
New Member
1 0 0

Thank you in advance for posting this.

 

Just to clarify, you go to "yoursite.myshopify.com/admin/settings/checkout" and under additional scripts, you add:

 

<script> window.location =" www.red.com"; </script>

 

It seems too easy. How can I test this script without having to make a payment?

 

 

0 Likes