Features

Live Stock Refresh

Published · Last updated

An opt-in feature that keeps stock state and Add-to-Cart buttons live on fully-cached pages — the same idea as AJAX pricing, applied to stock.

The problem it solves

If you full-page-cache your shop and product pages, the cached HTML freezes whatever stock state was current when the page was cached. A product that sells out can keep showing “In stock” (and a working Add to Cart button) to every visitor until the cache is purged. Excluding those pages from the cache fixes the accuracy but throws away the performance.

Live Stock Refresh lets you keep the pages cached and still show correct, current stock: in the same batched AJAX request that fetches prices, the plugin also fetches fresh stock text and Add-to-Cart markup for each product and swaps them in.

What gets refreshed

When enabled, for every product on the page the plugin refreshes:

  • Stock availability text — e.g. “5 in stock”, “Out of stock”, or nothing, exactly as WooCommerce would render it now.
  • The loop Add to Cart button — including the case where a now-out-of-stock product should show “Read more” instead of “Add to cart”.

There is no extra round-trip — stock rides along in the same ssap_get_prices request as prices.

Performance Tip

Stock never costs a second request. It rides along in the same batched price call, so keeping stock live on a cached page adds no round-trips, only a little more server work to render each product’s stock markup.

How to enable

  1. Go to Super Speedy → AJAX Prices.
  2. Tick Refresh stock via AJAX.
  3. Save.

Exclusions

Stock refresh follows the same rules as prices:

  • It only applies to published products.
  • It’s skipped for logged-in users if you’ve enabled Disable for logged-in users.
  • It’s skipped when the cart has items if you’ve enabled Disable when cart has items.

This keeps the price and stock halves of every response consistent — you never get refreshed prices with stale stock or vice-versa.

How to verify it’s working

  1. Enable the setting.
  2. Load a cached category page. In the page source you’ll see stock elements tagged with class="… ajax-stock" and loop Add-to-Cart links tagged with ssap-add-to-cart.
  3. In DevTools Network, the ssap_get_prices response now contains a stock object alongside prices.
  4. To prove it’s live: change a product’s stock in the admin (or let one sell out), then reload the cached page. The stock text and button update to the new state even though the HTML came from cache. After the swap the elements carry the ajax-stock-loaded class.

Notes & limitations

  • Stock refresh adds a little server work per request (it renders each product’s stock and Add-to-Cart markup), which is why it’s off by default. On normal-sized grids this is negligible; the per-request product cap still applies (see Developer Reference → ssap_max_products_per_request).
Note

Stock refresh is off by default because it renders each product’s stock and Add-to-Cart markup on every request. Turn it on only if you cache pages where stock genuinely changes during the cache’s lifetime; if your stock rarely moves, leave it off and save the work.

  • The refreshed markup is WooCommerce’s own server-rendered HTML, so it matches your theme’s styling.
  • For Product Bundles and Composite Products, the response also carries richer per-child/per-component stock data — see Compatibility & Integrations. Developers can add their own per-product fields via the ssap_stock_data_for_product filter (Developer Reference).
  • The ssap_stock_updated JavaScript event fires after stock is swapped in, so custom scripts can react to live stock data (Developer Reference).

Further reading

how Product Bundles, Composite Products and infinite scroll extend the stock payload.
the ssap_stock_data_for_product filter, the product cap and the JavaScript events.
add live stock data for your own product types.

Comments

▲
▼
1/1