Ad

Any Way To Redirect A Customer To A Link Based On A Keyword In A Checked Out Product Title?

- 1 answer

I need to be able to redirect a customer who buys a certain product to a form for more detailed data collection. Not too experienced with programming but I currently have this in my additional scripts section.

I have searched through all this documentation but have no idea how to implement it. https://help.shopify.com/en/themes/liquid/objects/checkout

Currently have this for the keyword autocheckout:

  {% if line.product.handle.includes('**autocheckout**') %}
     <script> window.location ="https://docs.google.com"; </script>
{% break %}
  {% endif %}
{% endfor %}

I expected this to redirect but it doesn't work.

Ad

Answer

You are close, just need to specify .href,

you currently have

<script> window.location = "https://docs.google.com"; </script>

just make it this to make it work, it simulates a mouse click

<script> window.location.href = "https://docs.google.com"; </script>

furthermore you can experiment and try this one out too, it simulates a HTTP redirect

<script> window.location.replace = "https://docs.google.com"; </script>
Ad
source: stackoverflow.com
Ad