"CONTINUE SHOPPING” link on CART page to re-direct customer back to the last URL

New Member
3 0 0

We would like to create a "CONTINUE SHOPPING” link on the CART page, so that it can re-direct customer to the last URL (not just the collection page). 

 

We are able to add a link that goes to the last collection viewed by adding the following HTML on cart.liquid, then javascript on theme.liquid from this URL: https://help.shopify.com/en/themes/customization/cart/add-back-link

 

We tried to modify the javascript but it did not work and we could not solve our problem as we would like customer to go back to the previous page instead.  Would anyone please help us on this? Thank you very much.

 

 

<a id="continue-shopping" href="" title="Continue shopping">Continue shopping</a>
<script>  
  if(Storage !== undefined) {

    var defaultLink = "/collections/all";

    {% if template contains 'collection' %}
      sessionStorage.collection = "{{ collection.url }}";
    {% endif %}

    {% if template contains 'cart' %}
      if( !sessionStorage.collection ) {
        sessionStorage.collection = defaultLink;
      }
      document.getElementById("continue-shopping").href = sessionStorage.collection;
    {% endif %}

    }
</script>

 

 

0 Likes
Shopify Partner
462 80 94

If you want to go previous page, you can just the following code to a tag

onclick="window.history.go(-1); return false;"

 

So the final version of the a tag will be 

 

<a id="continue-shopping" href="" title="Continue shopping" onclick="window.history.go(-1); return false;">Continue shopping</a>

 

and the script part can be removed

Author: Hovhannes Sargsyan (aka sarhov).
An individual web developer focused on Shopify development.
Need more help? Feel free to send me a direct message or drop an email shopify@sarhov.com

Website: https://sarhov.com  
Email: shopify@sarhov.com
Skype: @sarhov
Messenger: @sarhov
Telegram: @sarhov
0 Likes
New Member
3 0 0

Thank you very much and it works! 

 

I have one more question, if i let customer go "back" to the product's page after they put an item to the cart.  Will the "already-add-to-cart" product be kept in the cart page? 

I did some tryouts and it seems to be working.  Thanks.

0 Likes
Highlighted
Shopify Partner
462 80 94

Once you added product in the cart, it will be there even if you go back.

Even if you close the tab of that site and then again enter into it, it will be there ))

Author: Hovhannes Sargsyan (aka sarhov).
An individual web developer focused on Shopify development.
Need more help? Feel free to send me a direct message or drop an email shopify@sarhov.com

Website: https://sarhov.com  
Email: shopify@sarhov.com
Skype: @sarhov
Messenger: @sarhov
Telegram: @sarhov
0 Likes