How Gatemi Next Order Coupons Works

The whole plugin hangs on one moment: an order reaching a status. In the free edition that status is always Completed; in the full edition it is Completed or Processing, as you choose. When WooCommerce fires that status change, the plugin runs four steps in a fixed order: decide, claim, mint, send.

Nothing runs on the storefront. The plugin adds no scripts or styles for shoppers, and it makes no external requests (the full edition contacts gatemi.com only for licence checks and updates, and only once a key is entered).

1. Decide: does this order earn a coupon?

An order earns nothing when:

  • the coupon switch is off, or
  • the billing email is missing or is not a valid address — a coupon minted for nobody is a row in your coupons table you would have to tidy by hand.

In the free edition, every other order that reaches Completed earns the coupon.

Full edition — two more questions:

  • Is the order worth enough? If its total is below Only for orders worth at least, it earns nothing and the customer is told nothing. A coupon that arrives and is then refused would read as a bug.
  • Is this the customer's first order? The plugin asks WooCommerce for earlier orders with the same billing email (Processing, Completed or On hold, refunds not counted). None means a first order. It deliberately does not look at whether the customer is logged in or at a cookie: those would send the welcome discount to a regular every time they check out in a private window.
    • A first order earns the welcome coupon when On a customer's first order is on.
    • Any other order — or a first order with that switch off — earns the thank-you coupon when On every order after that is on.

The welcome and thank-you coupons have the same value and the same rules. What differs is the email wording and the coupon's description.

2. Claim: one order mints one coupon

WooCommerce fires a status hook more than once in ordinary use. Move an order back to Processing and complete it again, and the "completed" hook has fired twice. A plugin that creates a coupon each time has given that customer two codes.

So before any coupon exists, the plugin writes a claim onto the order: the order meta _gmnc_coupon is set to pending and the order is saved. If the claim is already there — pending or a code — the plugin stops. Only the run that wrote the claim goes on to mint.

The claim stays even if something later fails. A customer who was not sent a code is a conversation; a customer sent two is money.

3. Mint: a coupon bound to one person

The plugin creates an ordinary WooCommerce coupon:

  • Code: THANKS- plus eight random letters and digits (full edition: your own prefix). The random part means nobody can work out a valid code from their own.
  • Discount type and amount: from your settings.
  • Allowed emails: the billing email of the order that earned it.
  • Usage limit: 1 in total, and 1 per user.
  • Individual use only: it cannot be combined with other coupons, so it cannot be stacked on top of a sale code.
  • Expiry date: today plus Expires after days, counted in your store's timezone — or none.
  • Minimum spend (Full edition): Spendable on orders worth at least, when above 0.
  • Description: "Next-order coupon, earned by order 1042." (full edition welcome coupons: "Welcome coupon, earned by order 1042."), so you can tell where a coupon came from weeks later.

Once saved, the order's _gmnc_coupon meta is replaced with the code.

Because the code is restricted to one address, sharing it does nothing: a friend who tries it at the checkout is refused by WooCommerce's own email check. WooCommerce checks the allowed email against the billing email the customer types at the checkout.

4. Send: a message the customer can act on

Finally the plugin emails the billing address, as plain text through wp_mail(). The message contains the three things a customer needs — the code, what it is worth and the last day it works — because "your coupon is attached" with the expiry hidden on a screen the customer cannot see is a discount nobody uses.

A failed send never mints a second coupon: the claim is already on the order. If your mail does not go out, the coupon still exists and can be found under Marketing → Coupons.

Full edition: the welcome and thank-you emails each use your own subject and message when you have written them, and the gmnc_email filter can change or cancel the message (the coupon stays minted).

Worked example

Your settings: 10% off, expires after 30 days, full edition with first-order coupons on, a minimum of €40 to earn and €25 to spend, prefix WELCOME.

  1. Sarah places her first order, €62, as a guest. You mark it Completed.
  2. No earlier order has her billing email, and €62 is above €40, so it is a first order and earns the welcome coupon.
  3. The order is claimed (_gmnc_coupon = pending).
  4. Coupon WELCOME-3HD8QX2P is created: 10% off, only for her email, one use, individual use, minimum spend €25, expiring 30 days from today.
  5. She receives "Welcome — here is 10% off your next order" with the code and the date.
  6. You reopen the order and complete it again. The claim is already there; nothing happens.
  7. Her second order, €30, is below the €40 minimum. It earns nothing, and no email is sent.

Where things are stored

What Where
Settings Option gmnc_settings (shared by both editions)
The claim and the code Order meta _gmnc_coupon (pending, then the code)
The coupon An ordinary WooCommerce coupon
Licence (full edition) Option gmnc_license

The plugin creates no database tables.

Full edition: the code an order earned is shown in a Next-order coupon box in the side column of the order screen, on both the HPOS and the classic order screens. Orders that earned nothing show no box.

Shopping Cart
Scroll to Top