fbpx

How to best redirect customers to a page after payment in Shopify

How to best redirect customers to a page after payment in Shopify

How to best redirect customers to a page after payment in Shopify

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

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. Go to your Shopify admin and navigate to Checkout. Here, you can enter the code in the scripts section. The code is as follows: 

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. 

Where to insert the code

It’s quite simple to copy and paste this code into your Shopify admin page, however, you must know where to put it. 

  • Go to Settings 
  • Click on Checkout and go to Order Processing 
  • Select Additional Scripts 
  • Insert your code here to apply the changes 

redirect customers

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 ‘thank you for shopping’ page. 

 

Related Posts
Leave a Reply