Opencart 4 · 9 min read · Updated

Replenishment Reminders for OpenCart 4: “Running Low?” Emails With a One-Click Reorder (Free Extension)

A free OpenCart 4 extension that emails customers when a consumable they bought should be running low, with a signed one-click reorder link, consent settings and a daily cron job.

Opencart 4 replenishment reminders

A customer buys a 500 g bag of coffee from your store. Four weeks later it runs out, and they buy the next bag wherever they happen to be: the supermarket, Amazon, a competitor whose email arrived that morning. If you sell anything that gets used up, such as coffee, filters, pet food, contact lenses, ink or supplements, the second order is the one you lose most often. OpenCart 4 replenishment reminders ask for it at the right time.

The free Replenishment Reminders extension sends that customer an email when the product should be running low, with a button that puts the same item, quantity and options straight back in their cart. You set the reorder interval per product, a daily OpenCart cron job sends the emails, and a log shows who got a reminder and who clicked. These OpenCart 4 replenishment reminders were built and tested on OpenCart 4.1.0.4.

Download: replenish.ocmod.zip (tested on OpenCart 4.1.0.4).

Replenishment reminder email: Hi Jane, it has been 30 days since you ordered Organic Coffee Beans 500 g from Your Store, with a blue Reorder Organic Coffee Beans 500 g button and a Stop reorder reminders link
The reminder email, as received by our test mail server.

What OpenCart 4 replenishment reminders do

  • Reorder interval per product. Coffee after 30 days, water filters after 90. Only products you list get reminders.
  • Daily cron job. The extension adds a job to Extensions > Cron Jobs that finds orders whose interval ended and sends the emails. A Send due reminders now button does the same on demand.
  • No reminder for people who already reordered. If the customer bought the same product again after the order, they get nothing.
  • One-click reorder. The button opens your store with the same product, quantity and options in the cart, even for guests.
  • Consent and opt-out. By default only customers subscribed to your newsletter get reminders, and every email has a “Stop reorder reminders” link.
  • Log and clicks. The settings page shows what is due now, the last 20 reminders, how many were sent and how many reorder links were clicked.

Install the extension

  1. Download replenish.ocmod.zip. Don’t unzip it.
  2. Go to Extensions > Installer, click Upload and choose the zip.
  3. Click the green Install button next to “Replenishment Reminders”.
  4. Go to Extensions > Extensions, choose Modules, find Replenishment Reminders and click Install. This creates three tables and the daily cron job.
  5. Click Edit, add your products with their intervals, check the email text, switch Status on and click Save.
  6. Make sure store email works in System > Settings > Mail. The settings page shows a warning while it is off.

Settings

Replenishment Reminders settings in OpenCart 4 admin: reorder intervals for Organic Coffee Beans, Sea Salt Flakes and Webo Classic Tee at 30 days, email settings, and on the right a Due now panel and a log of two sent reminders marked Clicked
Settings on the left, what is due and what was sent on the right.
SettingWhat it does
Reorder intervalsType a product name, pick it and set “Remind after (days)”, from 1 to 365. Use how long a typical order lasts, not the shortest time.
Send to“Only customers subscribed to the newsletter” (the default) or “Every customer and guest who ordered”.
Subject, Message, Button textThe email text. You can use {firstname}, {product}, {days} and {store}. A blank line starts a new paragraph.
Catch-up window (days)How long after the interval ends an order can still get a reminder. The default is 14.
Emails per runThe most reminders one run sends. The default is 50.

Why newsletter subscribers only by default

A reminder to buy again is a marketing email, not an order update, and in many countries you need consent for those. That includes GDPR and PECR in Europe and the UK. In the US, CAN-SPAM also requires a working opt-out. Sending only to newsletter subscribers keeps you on the safe side. Choose “Every customer and guest” only if your consent wording at checkout covers this kind of email.

Why there is a catch-up window

Without it, the first run after you install the extension would email everyone who ever bought coffee from you, including people who ordered three years ago. With the default window of 14 days, an order with a 30-day interval gets its reminder between day 30 and day 44, and older orders are skipped.

Which orders get a reminder

An order line gets a reminder when all of these are true:

  1. The order has one of your “complete” statuses from System > Settings > Option.
  2. The product is in your reorder list, and its interval ended within the catch-up window.
  3. No reminder was sent for that order line before.
  4. The email address didn’t unsubscribe from reminders.
  5. The same email address didn’t order the same product again later in a processing or complete order.
  6. With the default consent setting, the email belongs to a customer account that is subscribed to the newsletter and enabled.

If two old orders for the same product are due at once, the customer still gets only one email. We tested the rules with four orders on the demo store:

OrderResult
Jane, newsletter subscriber, coffee and a T-shirt, 31 days agoDue: two reminders
Sam, guest, coffee, 32 days agoSkipped with the default setting, due with “Every customer and guest”
Demo Buyer, sea salt, 35 days ago, bought salt again sinceSkipped: already reordered
Jane, coffee, 200 days agoSkipped: outside the catch-up window

Running the job a second time sent nothing, because each order line is logged once.

The reorder button

The button links to the extension’s reorder route with the order ID, product ID, email and a token. The token is an HMAC of those three values with a random secret that the extension creates on first use, so nobody can change the order ID in the link to see or reorder someone else’s order. A link with a wrong token goes to the home page.

Recording the install video found a bug that a direct test had hidden. OpenCart 4.1 sets its storefront session cookie with SameSite=Strict, so when a shopper clicks the button in Gmail, Outlook or any other site, the browser sends the request without that cookie. The product went into a brand-new, empty session, and the cart the shopper then saw was empty. The fix answers the first request with a tiny page that reloads the same link from your own site, so the second request carries the shopper’s cookie, and it drops the new session cookie the first request created, so it can’t replace the real one:

if (empty($this->request->get['go'])) {
    header_remove('Set-Cookie');

    $next = htmlspecialchars($reminder->link('reorder', $line) . '&go=1', ENT_QUOTES, 'UTF-8');

    $this->response->addHeader('Cache-Control: no-store');
    $this->response->addHeader('X-Robots-Tag: noindex');
    $this->response->setOutput('<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta http-equiv="refresh" content="0;url=' . $next . '"><title>…</title></head><body><p style="font-family:sans-serif;margin:2rem"><a href="' . $next . '">Continue to your cart</a></p></body></html>');

    return;
}

We tested it the way a real email works: with an iPhone already in the cart, the reminder was opened from another origin and its button clicked. The cart then had the iPhone and the reordered T-shirt, and the session cookie was unchanged.

The route copies the options from the original order line, checks that each option value still exists on the product, and adds the product with the ordered quantity:

$quantity = max((int)$line['quantity'], (int)$product['minimum'], 1);

$this->cart->add((int)$line['product_id'], $quantity, $options, 0);

// Shipping and payment methods depend on the cart, as core does after cart changes.
unset($this->session->data['shipping_method'], $this->session->data['shipping_methods'], $this->session->data['payment_method'], $this->session->data['payment_methods']);

$this->response->redirect($this->url->link('checkout/cart', $language, true));

If the product was disabled, an option was removed or a new required option was added, the shopper lands on the product page instead, so they can choose again. Clicking the T-shirt reminder in our test put “Webo Classic Tee, Color: Navy, Size: Medium” in the cart, the same as the original order, and the coffee reminder added two bags because the order had two.

OpenCart 4 shopping cart after clicking two reminder links, with Organic Coffee Beans quantity 2 and Webo Classic Tee with Color Navy and Size Medium
The cart after clicking both reminders.

Unsubscribe

The “Stop reorder reminders” link opens a page that asks the customer to confirm with a button. The link alone doesn’t unsubscribe anyone, because email security scanners in many companies open every link in a message, and a one-click GET link would unsubscribe people who never clicked it. After the button, the email address is added to an opt-out list and never gets a reminder again. Order confirmations and other store emails are not affected.

Reorder reminders page in the OpenCart 4 storefront asking: Stop reorder reminder emails to jane.doe@example.com? with a Stop reorder reminders button
The confirmation step of the unsubscribe link.

Cron and email

The daily job runs through OpenCart’s own cron runner, the same one that updates currency rates. Your host needs to call it once a day. On our 4.1.0.4 test store we ran cron.php from the command line like this, because without the extra autoloader line cron.php in 4.1.0.4 stops with a “Twig\Loader\FilesystemLoader not found” error:

cd /path/to/opencart
php -d auto_prepend_file=/path/to/storage/vendor/autoload.php cron.php

Testing that run found a second problem, this time in OpenCart’s SMTP library. It greets the mail server with EHLO followed by the SERVER_NAME environment variable, and on the command line that variable is empty. Our test mail server refused the empty greeting with “EHLO not accepted from server!”. RFC 5321 requires a domain name there, and strict mail servers refuse an empty one. The extension sets SERVER_NAME to your store’s host name before sending when it is empty:

// Core's SMTP library sends "EHLO " . getenv('SERVER_NAME'), which is empty when cron.php runs
// from the command line. RFC 5321 requires a domain there and strict mail servers refuse it. Use the store host.
if ((string)getenv('SERVER_NAME') === '') {
    $url = defined('HTTP_SERVER') ? HTTP_SERVER : (string)$this->config->get('config_url');

    putenv('SERVER_NAME=' . (parse_url($url, PHP_URL_HOST) ?: 'localhost'));
}

A failed email is logged as “Failed” and written to the OpenCart error log with the reason, and it isn’t retried every day. We tested sending with an SMTP sink container, from the admin button and from the cron runner. Both delivered the emails.

To land in inboxes rather than spam, set up SPF, DKIM and DMARC for the domain your store sends from, as explained in email deliverability for ecommerce.

Limitations

  • OpenCart’s mail class has no way to add custom headers, so the opt-out link is in the email body, not in a List-Unsubscribe header. Gmail and Yahoo expect that header from senders of large volumes. For thousands of reminders a day, send them through your email platform instead.
  • The interval is per product, not per quantity. Two bags of coffee get a reminder at the same time as one.
  • Reorder link clicks are counted when the link is opened, so a link scanner that opens links also counts as a click.
  • The email text is one language.
  • Uninstalling the module deletes its tables, including the opt-out list.
Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *