Last Updated on by Dan S
Originally Published June 18, 2021.


Is it possible to redirect customers to a page after they’ve completed a payment in Shopify? Or will you have to use an app?

Let’s discuss this in detail. 

How to redirect customers to a certain page after payment

This can be achieved natively in Shopify without the use of an app. Depending on your complexity of your use case, an app may be a better solution but in most cases, the below should work fine.

If you want to complete this through Shopify, you’ll need to use JavaScript to make this happen. 

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

 

In this case yoururlhere.com is the URL of the page you want to send the customer to.

redirect after checkout

Go to your Shopify admin and navigate Settings then select Checkout. Next, scroll down to the Additional Scripts section.

Enter the below code in the Additional Scripts section. 

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
} 

In this code, the redirect_url refers to the URL where you want to send the customer. Meanwhile, redirect_prod_ids refers to the items on which that code is applicable. You can write one product ID or separate multiple product IDs with commas. 

The code works even if the customer has bought multiple items in that order. To get the product ID, go to the admin. 

You can choose to redirect your customers to any page after they’ve completed shopping. For instance, you may want to send them back to the collection or to a custom ‘thank you for shopping’ page. 

There is another Script variation available on Stackoverflow here.