Have your say in Community Polls: What was/is your greatest motivation to start your own business?

How to have 'Continue Shopping' link return to previous page or collection?

Solved

How to have 'Continue Shopping' link return to previous page or collection?

Smeelah
Navigator
358 1 100

I've seen this question asked several times but I haven't seen an answer. 

 

Currently the continue shopping button directs the customer to a list of all the collections, which interrupts the shopping experience imho, causing the customer to have to navigate back to where they were. 

 

Is it possible to change the link to at least send the customer to the previous page?

 

(I'm on Dawn 6.0.2)

 

Thanks for any help!

Accepted Solution (1)

made4Uo
Shopify Partner
3856 717 1197

This is an accepted solution.

Hi @Smeelah 

 

To change to a back button instead of going to the all collections for the "Continue shopping", please follow the instructions below.

 

1. From your Admin Page, click Online Store > Themes >Actions > Edit code
2. In the Section folder, open the main-cart-items.liquid
3. Find and replace all codes {{ routes.all_products_collection_url }}, Ctrl + F to find

 

javascript:history.back()

 

 4. Place the {{ routes.all_products_collection_url }},  and the javascript:history.back()  in the second box, then click replace all

 

Please check the image below

made4Uo_0-1662134879053.png

 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free

View solution in original post

Replies 5 (5)

made4Uo
Shopify Partner
3856 717 1197

This is an accepted solution.

Hi @Smeelah 

 

To change to a back button instead of going to the all collections for the "Continue shopping", please follow the instructions below.

 

1. From your Admin Page, click Online Store > Themes >Actions > Edit code
2. In the Section folder, open the main-cart-items.liquid
3. Find and replace all codes {{ routes.all_products_collection_url }}, Ctrl + F to find

 

javascript:history.back()

 

 4. Place the {{ routes.all_products_collection_url }},  and the javascript:history.back()  in the second box, then click replace all

 

Please check the image below

made4Uo_0-1662134879053.png

 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free
Smeelah
Navigator
358 1 100

Hi @made4Uo 

 

That is awesome. Thank you. Works perfectly for my 2.0 theme. 

 

Also, I'll post a link to a Shopify tutorial that works for older themes. 

DesignGal
Visitor
2 0 0

Hey there @made4Uo – I also tried this code replacement but it didn't work for me? Am using Broadcast theme on Shopify 2.0. Any idea why it wouldn't have worked? When I replaced the code snippet as per your instructions and tested the CONTINUE SHOPPING button it took me to a blank error page (not back to the previous page). 

vera_p
Tourist
13 0 1

Hi!

this worked in a way

Butttt the page it redirected me to was the product page. I want it to go back to the previous non-product page. Is that possible?

That would revert to the specific collection page the user was before.

 

Thanks a lot!

vera_p
Tourist
13 0 1

Hi!
Actually was able to change this!

Let me know if you have suggestions to improve this 🙂  I am just a beginner

 

In my theme.liquid file I added at the end:

<script>
  document.addEventListener("DOMContentLoaded", function () {
    // Get the current page URL including filters (query parameters)
    const currentPage = window.location.pathname + window.location.search;

    // Load navigation history from sessionStorage
    let history = JSON.parse(sessionStorage.getItem("navigationHistory")) || [];

    // Add the current page to history if it's not already the last entry
    if (history[history.length - 1] !== currentPage) {
      history.push(currentPage);
    }

    // Limit history to the last 10 pages (optional)
    history = history.slice(-10);

    // Save updated history back to sessionStorage
    sessionStorage.setItem("navigationHistory", JSON.stringify(history));
  });
</script>

 

Then, I substituted the <a href (...)  </a> section in the main-cart-items.liquid:

<a href="javascript&colon;void(0);" class="underlined-link" onclick="
  // Load navigation history from sessionStorage
  const history = JSON.parse(sessionStorage.getItem('navigationHistory')) || [];
  let targetPage = '/collections/todas-as-pecas'; // Default fallback

  // Traverse history backwards to find the last collection page
  for (let i = history.length - 1; i >= 0; i--) {
    if (history[i].includes('/collections') && !history[i].includes('/products')) {
      targetPage = history[i]; // Capture the full URL including filters
      break;
    }
  }

  // Redirect to the target page
  window.location.href = targetPage;
">
  {{- 'general.continue_shopping' | t -}}
</a>