Skip to main content

Recently Viewed Products

Goal​

Record which products a visitor has looked at and show them again. Views are stored server-side against the signed-in user, or against a cookie-held session ID for guests, so the list survives across devices for an account and across pages for a guest.

Tier and entitlement​

FieldValue
TierPremium
Entitlement keyrecently-viewed
Admin tabrecently-viewed
Module keyrecently-viewed
Settings prefixaiowc_rv_

Hooks register only when aiowc_module_enabled_recently-viewed is true and the licence permits the recently-viewed entitlement.

What the code does​

  • A view is recorded on template_redirect when a single product page is rendered, and can also be recorded through a REST call.
  • Signed-in users are tracked by user ID. Guests are tracked by an anonymous session ID held in the aiowc_rv_sid cookie, and only when anonymous_tracking is on.
  • The list renders after the single product template, and anywhere through a shortcode.
  • The visitor can clear their own list.
  • The shop can see the most-viewed products over a period.
  • A daily job prunes view rows older than 90 days. The retention window is a constant in Jobs/CleanupJob.php, not a setting.

Settings​

Unlike most modules, all five values are stored together in one array option, aiowc_rv_settings, read through RecentlyViewedModule::getAllSettings() and merged over DEFAULTS. An update only accepts keys that exist in DEFAULTS and casts each to the type of its default.

SettingDefaultMeaningConsumed
enable_trackingtrueMaster switch for recording and displaying viewsYes — both the tracking and display services
max_products10How many products the list showsYes — the display service, with a floor of 1
anonymous_trackingtrueWhether guests are tracked by cookieYes — the display service falls back to the cookie list only when on
show_on_accounttrueIntended to place the list on the My Account pageNo — the key is declared but never read as a condition, and no account hook exists
show_on_homepagetrueIntended to place the list on the homepageNo — the key is declared but never read as a condition, and no homepage hook exists

The list appears in exactly two places: after the single product template, and wherever the shortcode is placed.

Admin screen​

Admin tab recently-viewed. It shows the most-viewed products over a chosen number of days and the settings above.

Database schema​

Created by Schema/RecentlyViewedSchema.php at schema version 1.0.0.

TableHolds
{prefix}aiowc_product_viewsOne row per product view, keyed by user ID or anonymous session ID

REST endpoints​

Namespace aiowc/v1. All responses use the shared envelope.

MethodPathPurposeRequired argsPermission
POST/viewed/trackRecord a product viewproduct_idPublic write check
GET/viewed/recentThe caller's recently viewed products, up to limit—Rate-limited public read
POST/viewed/clearClear the caller's list—Public write check
GET/viewed/admin/topMost-viewed products over days, up to limit—Manage
GET/viewed/settingsRead settings—Manage
POST/viewed/settingsUpdate settings—Manage

WooCommerce and WordPress integration​

HookPriorityEffect
template_redirectdefaultRecords a view when a single product page loads
woocommerce_after_single_product20Renders the recently viewed list

Shortcode​

ShortcodePurpose
[aiowc_recently_viewed]Renders the recently viewed list

No block is registered, and the module hooks no order, cart or email action.

Background jobs​

HookSchedulePurpose
aiowc_views_cleanupDaily, on the WordPress cron schedulerPrunes view rows older than 90 days

Privacy note​

Guest tracking writes a cookie (aiowc_rv_sid) and stores a row per product view. Turning anonymous_tracking off stops the guest fallback.

Entitlement limits​

The recently-viewed entitlement gates the module as a whole. max_products is a display setting, not a licence limit, and no cap on stored view rows is implemented beyond the 90-day cleanup.