Code for redirecting buyer to external website after successful purchase

Steven_Stark
New Member
2 0 1

Hi All, 

I'm new to Shopify and am NOT a programmer.  However, I need to make it so that after my buyer's buy a product, they need to be redirected to a specific external website for that specific product.  I have three products on Shopify and there is a unique external website for each of those three products. 

I tried using the code below, but it's not quite working.  Once the purchase is made the buyer gets to the Thank you! page from Shopify, but the buyer is never redirected to the external website as desired. 

Would anyone have any input on why the below code isn't doing the redirect after purchase as desired? 

Thanks for any help you can provide! 

Steven 

========================================================

{% for line in line_items %}
  {% if line.product.variant.id == "3896948737" %}
   <script>document.location = 'http://app.webinarjam.net/verified/g3zt44bsfvygc5l248sw253/mnqtg4bwmvst2yrAfvygc5l248sw253'</script>;
{% elsif line.product.variant.id == "4022744129" %}
<script>document.location = 'http://app.webinarjam.net/verified/g3zt44bsfvygc5l248sw253/mnqtg4bwmvst2yrAfvygc5l248sw253'</script>;
{% elsif line.product.variant.id == "4129900225" %}
document.location = <script>'http://app.webinarjam.net/verified/g3zt44bsfvygc5l248sw253/gnrg3nrrmmyt4nddfvygc5l248sw253'</script>;
  {% endif %}
{% endfor %}

==================================================================================

 

0 Likes
Britton_Jenner
Shopify Staff (Retired)
Shopify Staff (Retired)
398 0 76

Hi Steven,

Britton here with the Shopify support team.

For how the checkout system in Shopify is set up your customers must be redirected to our thank you page after purchase. Any substantial edits to the checkout's functionality would be a feature of our Shopify Plus plan: https://www.shopify.ca/plus.

However, you can add extra content to that page based on which product has been ordered; the extra content could easily be a link to your external product page. We have a walkthrough in how you can go about setting that up in our documentation: https://docs.shopify.com/manual/configuration/store-customization/page-specific/checkout-page/thanky....

For the code above, it looks like there needs to be two changes:

  • {% for line in line_items %} should be replaced with {% for line in checkout.line_items %} 
  • line.product.variant.id should be replaced with line.variant_id

If you ever need to double check liquid object syntax in the future remember that we have liquid documentation available: https://docs.shopify.com/themes/liquid-documentation/objects/line_item#variant-id.

I hope that helps!

-Britton

 

Britton Shopify Guru
0 Likes
Steven_Stark
New Member
2 0 1

Hi Britton, 

Thank you so much for your response.  I understand that the buyer must be taken to the Shopify Thank You page after successful purchase, but from that page can they then be automatically redirected to an external URL?  

I made the two changes you suggested for the code, but there is still no redirect taking place after purchase.  The buyer just gets to the Thank You page and nothing happens after that. 

And just to confirm, I'm not using a Shopify storefront.  My users are directed to Shopify from an external website just for the purpose of accepting their credit card payment.  After successful payment I'm trying to redirect them back to that external site and that's what I'm having trouble with. 

Any ideas on what might be preventing this?  Or can it not be done? 

Thanks,

Steven

Here's the code based on your suggestions: 

{% for line in checkout.line_items %} 
  {% if line.variant_id == "3896948737" %}
   <script>document.location = 'http://app.webinarjam.net/verified/g3zt44bsfvygc5l248sw253/mnqtg4bwmvst2yrAfvygc5l248sw253'</script>;
{% elsif line.variant_id == "4022744129" %}
<script>document.location = 'http://app.webinarjam.net/verified/g3zt44bsfvygc5l248sw253/mnqtg4bwmvst2yrAfvygc5l248sw253'</script>;
{% elsif line.variant_id == "4129900225" %}
document.location = <script>'http://app.webinarjam.net/verified/g3zt44bsfvygc5l248sw253/gnrg3nrrmmyt4nddfvygc5l248sw253'</script>;
  {% endif %}
{% endfor %}

beero_megu
New Member
2 0 0

Hi Steven,

Did you get a reply to this issue?

I am looking for a solution to do the same thing you are trying to do here, and if you found out how to solve this issue, I really want to ask you how..

 

Thanks and best regards

0 Likes