Refer a Friend for OpenCart 4 and 3: Referral Links, Welcome Coupons and Rewards (Free Extension)
Give $10, get $10 in OpenCart: personal referral links, one-time welcome coupons and automatic store credit or reward points when the first order completes.

Your happiest customers already recommend you to friends. Without a referral program you can’t see it, you can’t thank them, and the friend has no extra reason to buy now instead of later. OpenCart has coupons, store credit and reward points built in, but nothing that ties them together into “give $10, get $10”.
Refer a Friend is a free extension that does exactly that. Every customer gets a personal link in My Account. A friend who signs up through it gets a one-time welcome coupon that’s already applied to the cart. When the friend’s first order is complete, the referrer gets store credit or reward points automatically. It comes in builds for OpenCart 4.1.0.4 and OpenCart 3.0.5.1, and we tested the full flow on both, from the shared link to the reward.
Download Refer a Friend
- OpenCart 4.1.0.4: referafriend.ocmod.zip for OpenCart 4
- OpenCart 3.0.5.1: referafriend.ocmod.zip for OpenCart 3

How the referral flow works
- The customer shares a link. In My Account there’s a new Invite friends and earn rewards link. It opens a page with their personal link, such as
https://your-store.com/?ref=9ADCAB7D, a Copy button and Email, WhatsApp and X share buttons. - The friend clicks it. The store remembers the code in a cookie for 30 days (you can change that) and shows a banner: “Jane invited you! Create an account to get 10% off your first order.”
- The friend creates an account. A one-time coupon is created just for them and applied to their cart right away, and a welcome banner shows the code.
- The friend’s first order is completed. When the order reaches a reward status (Complete by default), the referrer gets the reward as store credit or reward points, with a note in their account history.


Install in OpenCart 4
- Go to Extensions > Installer, upload
referafriend.ocmod.zipand click the green +. - Go to Extensions > Extensions, choose Modules, and install Refer a Friend.
- Click the pencil, turn Status on, set the friend’s discount and the referrer’s reward, and save.
- Check that Extensions > Extensions > Order Total > Coupon is enabled, plus Store Credit or Reward Points for the reward you chose.
Install in OpenCart 3
- Go to Extensions > Installer and upload
referafriend.ocmod.zip. There’s no OCMOD file, so no modification refresh. - Go to Extensions > Extensions, choose Modules, and install Refer a Friend.
- Edit it, set Status to Enabled, fill in the discount and reward, and click Save.
- Make sure the Coupon order total, and Store Credit or Reward Points, are enabled.
Settings

- Link parameter: the name in the link,
refby default. Use 1 to 20 lowercase letters, numbers or underscores. - Remember the link for (days): how long the cookie lasts after a click. The default is 30.
- What the friend gets: a percentage or a fixed amount off, an optional minimum sub-total, and how many days the coupon stays valid. Each coupon works once, only for that logged-in customer.
- What the referrer gets: store credit in your default currency or a number of reward points, and an optional minimum total for the friend’s first order.
- Reward when the order status is: usually just Complete, so canceled and refunded orders earn nothing. The extension preselects your store’s complete statuses. On a default OpenCart 3 store that includes Shipped, so untick it if you only want to pay after delivery.
Below the settings there’s a Referrals table: who referred whom, the friend’s coupon, the sign-up IP, the status and the rewarded order.

What we tested
On OpenCart 4.1.0.4, Jane shared her link and Maya Lopez signed up through it. Maya’s coupon was created and applied automatically, taking $20.20 off two iPhones. We moved Maya’s order to Processing: no reward, as expected. We moved it to Complete: Jane’s account got $10.00 store credit with the description “Refer a Friend: Maya placed their first order (#900022)”. Setting Complete a second time didn’t pay again.
On OpenCart 3.0.5.1 we ran the same steps with a new customer, Liam Chen. The coupon took $20.20 off two iPhones, Pending and Processing paid nothing, and Complete added $10.00 to the referrer’s store credit, once.
We also tried to cheat it. A customer who opens their own link is ignored, an unknown code is ignored, and a friend who signs up with the referrer’s own email address gets no coupon.
How it works
No core files are changed. On OpenCart 4 the extension adds a startup action that reads the ?ref= code on any page, and four events: one after a customer is added, one after an order history is added, one on the header for the banners, and one on the account page for the link. The startup action ignores unknown codes and self-referrals before setting the cookie:
$code = strtoupper(preg_replace('/[^A-Za-z0-9]/', '', $this->request->get[$param]));
$referrer = $this->db->query("SELECT c.`customer_id`, c.`firstname` FROM `" . DB_PREFIX . "referafriend_code` rc LEFT JOIN `" . DB_PREFIX . "customer` c ON (c.`customer_id` = rc.`customer_id`) WHERE rc.`code` = '" . $this->db->escape($code) . "' AND c.`status` = '1'")->row;
// Unknown codes and people clicking their own link are ignored.
if (!$referrer || ($this->customer->isLogged() && $this->customer->getId() == $referrer['customer_id'])) {
return;
}
$days = max(1, (int)$this->config->get('module_referafriend_days'));
setcookie($this->cookie, $code, [
'expires' => time() + $days * 86400,
'path' => '/',
'secure' => !empty($this->request->server['HTTPS']),
'httponly' => true,
'samesite' => 'Lax'
]);
The reward runs after OpenCart saves an order status. Admin status changes go through the same catalog model, so they trigger it too. To make sure a referral can only pay once, even if two status changes arrive at the same moment, it first claims the referral with an update that only succeeds while the status is still pending:
$referral = $this->db->query("SELECT * FROM `" . DB_PREFIX . "referafriend` WHERE `friend_id` = '" . (int)$order['customer_id'] . "' AND `status` = 'pending'")->row;
if (!$referral) {
return;
}
// Claim the referral first, so two status changes at once can't pay twice.
$this->db->query("UPDATE `" . DB_PREFIX . "referafriend` SET `status` = 'rewarded', `order_id` = '" . $order_id . "', `date_rewarded` = NOW() WHERE `referral_id` = '" . (int)$referral['referral_id'] . "' AND `status` = 'pending'");
if (!$this->db->countAffected()) {
return;
}
What’s different in the OpenCart 3 build

- OpenCart 3 has no startup actions, so the link is captured in the
catalog/view/common/header/afterevent, which runs on every storefront page. - The reward listens to
catalog/model/checkout/order/addOrderHistory/after, OpenCart 3’s name for the same step. - Templates use Bootstrap 3 and Font Awesome 4, and the admin uses OpenCart 3’s normal save-and-reload form.

Things to know
- The coupon lives in the sign-up session. If the friend signs up, leaves, and comes back later on another device, the coupon isn’t in the new cart automatically. The welcome banner shows the code, so they can type it in the coupon box.
- The friend must stay logged in. Coupons are created for logged-in customers only, so a friend can’t pass their coupon on to someone else.
- Uninstalling removes the referral records, but coupons, credit and points that were already given stay in OpenCart.
Related posts
- How reward points work in OpenCart 4
- Coupons management in OpenCart 4
- Coupon links for OpenCart 4
- Wishlist reward points for OpenCart 4
Please let us know if you have any questions or suggestions, and subscribe to our YouTube channel for more OpenCart video tutorials. You can also find us on Twitter and Facebook.







