How Gatemi Birthday Coupons Works

The plugin does three things: it stores a date of birth on a customer's account, it runs one job a day, and that job mints and emails coupons. Three rules govern all of it.

Rule 1: one customer, one coupon a year

A daily WP-Cron job is exactly the job that runs twice. WP-Cron starts on page loads, so two visitors arriving in the same second can both start it; a store with a real system cron and WP-Cron left on has two runners by design. A plugin that checks "have I sent one?" and then sends will, sooner or later, send two.

So the year is claimed before the coupon exists, with one database insert that only one caller can win:

  1. The job finds a customer whose send day is today.
  2. It adds a WordPress option named gmbd_c_{year}_{kind}_{user id} — for example gmbd_c_2026_birthday_42 — with the fixed value 1.
  3. If that option already existed, the insert fails and the job moves on. Nothing is minted.
  4. If the insert succeeded, the job creates the coupon, records it on the customer and sends the email.
  5. If the coupon could not be created, the claim is deleted again, so the customer is tried again tomorrow rather than skipped for the year.

The value is constant on purpose: WordPress' add_option() would quietly update an existing row whose value differed and report success, which would let a second runner through.

Both editions use the same option names, so a customer who had this year's coupon from the free edition is never sent a second one after you upgrade.

Rule 2: a birthday is a day in your shop's calendar

Every date is worked out with wp_date() in the timezone set under Settings → General. The job is scheduled for just after midnight in that timezone. A shop in Auckland does not send its coupons on the wrong day.

29 February is observed on 28 February in a common year. Someone born on a leap day still has a birthday every year.

The head start crosses the year end. With a 7-day head start, a birthday on 3 January is sent on 27 December. That coupon is filed under the following year, so it is not sent a second time in early January.

A missed day is not made up. If the site's cron does not run on a given day, the customers due that day are not sent late coupons when it comes back. A "happy birthday" a week late is worse than none, and the fix belongs in the site's cron.

Rule 3: a date of birth is personal data

  • It is stored as user meta _gmbd_dob (format YYYY-MM-DD) on the customer's account — never on an order.
  • A future date, or a date that is not a real calendar date, is not stored.
  • At the checkout, an empty field leaves an existing date alone. In My Account, emptying the field deletes the date — the customer has asked to be forgotten.
  • A guest checkout stores nothing: there is no account to hold it.
  • WordPress' Tools → Export Personal Data includes the date, and Erase Personal Data deletes it.
  • Uninstalling the plugin deletes every stored date. The coupons already sent are ordinary WooCommerce coupons and are kept.

The coupon

Each coupon is a normal WooCommerce coupon with:

  • the code: BDAY- (or your prefix in the full edition) plus eight random characters, so nobody can guess a working code from their own;
  • the discount type and amount from your settings;
  • Allowed emails set to the customer's account email — a friend who is given the code cannot use it;
  • Usage limit per coupon 1 and per user 1;
  • Individual use only on;
  • an expiry date: today plus Expires after days;
  • Full edition: a minimum spend, when you set one;
  • the description "Birthday coupon." (or "Anniversary coupon.").

Because these are ordinary coupons, they work on the classic checkout, the Checkout block and the Store API with nothing to configure.

The latest one sent is recorded on the customer as _gmbd_last, in the form birthday:2026:BDAY-7KQ2MX9P.

The daily run, step by step

  1. Just after midnight store time, gmbdf_daily (free) or gmbd_daily (full) fires.
  2. The job asks WordPress for customers who have a stored date (a meta query), 2,000 at a time, oldest account first, and pages on until every one has been read.
  3. For each, it works out the send day this year: the observed birthday minus the head start (7 days in the free edition, your Send it this many days early in the full edition).
  4. If the send day is today, it claims, mints, records and emails, as above.

Full edition: anniversaries

With On the anniversary of the day they joined on, the same run also looks at the date each account was registered and sends an anniversary coupon on that date each year (minus the head start), with its own email wording and its own claim (gmbd_c_2026_anniversary_42). A developer can override the date for one customer in Users → (edit a user) → Birthday Coupons → Anniversary date, stored as user meta _gmbd_since (YYYY-MM-DD); left empty, the registration date is used. The anniversary date is exported and erased by WordPress' privacy tools on its own, not only beside a birthday.

The anniversary run does not use a meta query — every account has a registration date — so it pages through every customer account, oldest first, a batch at a time.

Housekeeping

Once a week, gmbd_sweep deletes claim options for years more than a year old, so the options table does not grow for ever. The current and last year's claims are always kept, because a December run files under next year. The free edition does the same sweep at the end of every daily run.

Next

Shopping Cart
Scroll to Top