Redirect back to the Wishlist Page after Login

Sometimes a scenario arises when the customers click the login link on the wishlist page and you want to them to return back to the same wishlist page after getting logged in. This requires a simple code tweak.

For simplicity, we assume that the path to Wishlist page is the default one /a/wishlist

Add the following Javascript code to the login form. In most themes, it is most likely to be in templates/customers/login.liquid

<script type="text/javascript">
  if(document.referrer.endsWith("wishlist"))
  {
      var return_element=document.createElement('input');
      return_element.setAttribute('name', 'checkout_url');
      return_element.setAttribute('type', 'hidden');
      return_element.setAttribute('value', document.referrer);
      document.querySelectorAll('[action="/account/login"]')[0].appendChild(return_element);
  }
</script>

The above code gets executed only if the user visits the login page from the Wishlist page. It adds a hidden element named checkout_url, which tells Shopify to redirect the user to a specific page after login.

Notwithstanding its name, checkout_url element doesn’t impact the checkout process of your store. Currently, this is the only known tweak to redirect the user to a specific page after login, on Shopify.

Leave a Reply

Your email address will not be published. Required fields are marked *