How do I redirect the "continue shopping" link on the cart notification pop up to the previous page?

Hello all,

When a customer adds a product to the cart, a cart notification pop up window appears. On the cart notification pop up window, there is a “continue shopping” link showen and when it clicked, it just goes back to the product they have selected. Instead, I want the “continue shopping” to go back exactly to the previous page not to the home page or other pages.

Please walk me through step by step on how solve it with pictures.

My URL: https://u7yeji-na.myshopify.com

1 Like

Hi @Mamdouh_USD ,

  1. Go to Online Store → Theme → Edit code.
  2. Open your theme.liquid file
  3. In theme.liquid, paste the below code before

Thanks!

Hi @topnewyork ,

After editting and saving the theme.liquid file, the added product did not appear in the cart on the mobile version. Can you help me solving this issue? Thank you.

I’ve been trying to adjust the “Continue Shopping” link that appears in the cart notification popup. Right now, it just sends users back to the product page, but I’d like it to take them back to the actual page they were on before adding the item—like a collection, blog, or landing page.

I tried adding a bit of JavaScript using window.history.back() so it pulls the browser’s previous page. It does send them back in most cases, but it’s not always reliable, especially if they refreshed the page or came from an external site.

  1. Go to Online Store → Theme → Edit code.
  2. Open your theme.liquid file
  3. In theme.liquid, paste the below code before

Thanks!

Wouldn’t previousPage always be current URL?

IMO no need for localStorage, just use

if (document.referrer) window.location = document.referrer;

Hi @tim_1 ,

Can you write the full code so I can copy it and paste it? Also where should I paste it exactly? Thank you

Ok here is my code:


And do not forget to remove any previous code.

This will return you to a literally previous page.

You can replace document.referrer with Shopify.routes.root to redirect people to homepage or Shopify.routes.root + “collections/all” to send them to your “all products” collection…

1 Like

It worked @tim_1 . Thank you very much :slightly_smiling_face: