A recently viewed products section for Shopify that needs no app. It remembers the products a shopper opens and shows them as a compact, swipeable row with prices and a Clear history button. Use it on product pages, the home page or the cart page to help shoppers get back to items they looked at. Copy section.liquid into your theme's sections folder and add it from the theme editor as "WDS Recently viewed".
How it works
On a product page, the section saves the product's handle in the browser's localStorage, newest first, keeping the last 12. On any page, it reads that list and loads each product from Shopify's /products/{handle}.js endpoint, then builds cards with image, title, price, compare-at price and a Sold out note. The product being viewed is left out of its own row.
The section stays hidden until there is something to show, so first-time visitors never see an empty block. Deleted products are dropped from the list on their own. Cards sit in a scroll-snap row: shoppers swipe on phones, and on wider screens round arrow buttons page through the row once it overflows.
Clear history removes the saved list and replaces the row with a short confirmation. In the theme editor, sample cards and a note show the layout, because your own browsing history is usually empty there.
Customization
In the theme editor:
- Heading and Subheading.
- Products to show (2 to 8).
- Hide the product being viewed and Show "Clear history" button.
- Labels: Clear history button, Message after clearing, Sold out, the price prefix for variable prices and the hidden screen reader texts.
- Background, Text, Accent (focus outlines), Card borders and Sale price colors.
- Side padding, Top padding and Bottom padding.
Accessibility
The row is a list named by the section heading, and every card is a single link with the product title as its text. The arrow buttons have screen reader labels and are disabled at the ends of the row. After Clear history, focus moves to the confirmation message, which is announced as a status. Focus outlines are visible, and smooth scrolling is turned off for people who prefer reduced motion.
Usage notes
This section requires an Online Store 2.0 theme. Add it to your product template so views are recorded; add it to other templates too if you want the row there.
The history lives only in the shopper's browser: it does not follow them to another device and is lost when they clear site data. Prices are formatted in the browser with your store's money format; if you sell in several currencies, check that the row shows prices the way your theme does.
The preview shows sample products from an invented store with photos from Unsplash written into the page; on your store the cards come from real browsing history. Its links go nowhere.