How Gatemi Back in Stock Works

The plugin is built around three rules. Each one prevents a real failure of back-in-stock plugins.

  1. An address is not proof of consent. Nothing is sent until the address is confirmed.
  2. Send once, twice over. A person is on a product's list once, and every email is claimed before it is sent.
  3. Nothing is emailed inside the request that changed stock. A sweep does the sending, a minute later.

The life of a signup

Every signup is one row in the waitlist table, with a status:

Status Meaning
pending Address given, not yet confirmed. Nothing will be sent except the confirmation email.
confirmed Confirmed, waiting for stock.
notified The back-in-stock email has been claimed and sent.

1. The shopper signs up

On an out-of-stock product the shopper enters an address and presses the button. The form posts to a WooCommerce AJAX endpoint (?wc-ajax=…), with a nonce. The address must be valid and the product must exist.

The row is written with one SQL statement — INSERT … ON DUPLICATE KEY UPDATE — against a UNIQUE (product_id, email) index. That is why signing up twice, or tapping the button twice quickly, is still one row. A check followed by an insert would let two simultaneous taps both pass.

If the same address signs up again for a product it was already emailed about (notified), the row goes back to pending (or confirmed) — they want to hear about the next restock too. A row that is still pending or confirmed keeps its status.

2. The address is confirmed

  • Signed-in customer, own address: confirmed straight away. WordPress already verified the address when the account was registered.
  • Anyone else: the row is pending and a confirmation email is sent to that address. The link in it carries a random token. Opening it moves the row to confirmed.

In the full edition the confirmation step can be switched off (setting double_opt_in). In the free edition it is always on.

The confirmation page looks the same whether the token was good, used or unknown. A link must not tell a visitor whether an address is on the list.

3. Stock comes back

The plugin listens to WooCommerce's stock events:

  • woocommerce_product_set_stock and woocommerce_variation_set_stock (the quantity changed and the product is now in stock), and
  • woocommerce_product_set_stock_status and woocommerce_variation_set_stock_status (the status became instock).

It does not send anything at that moment. A restock often happens in an import, a bulk edit or a REST call; emailing two hundred people inside that request is how "set stock to 40" becomes a timeout. Instead it schedules one sweep for the product, one minute out. If a sweep for that product is already scheduled, nothing new is added — so a bulk edit that touches one product forty times still produces one sweep.

When a variation changes, both the variation and its parent are swept. The form sits on the parent product page, so the parent is what shoppers signed up for.

4. The sweep

When the sweep runs:

  1. The product's stock is read again. If it is out of stock again, nothing is sent — telling somebody to hurry to an empty page is worse than telling them nothing.
  2. Up to one batch of confirmed rows is read, oldest first (50 in the free edition; the batch setting in the full edition).
  3. For each row the plugin claims it: one UPDATE … SET status = 'notified' … WHERE id = … AND status = 'confirmed'. Only if that statement changed the row is the email sent.

The claim is what makes "send once" true. WooCommerce's stock hooks fire more than once in normal operation (a quantity change, then a status change), and two sweeps can overlap. Sending first and marking afterwards would send a duplicate every time a request died in between. If an email is cancelled after the claim (by the gmbis_email filter in the full edition), the row stays claimed: a person not told is better than a person told twice.

5. The email and unsubscribing

The back-in-stock email names the product, your site and the product link, and always ends with an unsubscribe link. The link carries the row's token, never its id — an id is a number anybody could count through.

Opening the unsubscribe link deletes rather than flags. Somebody who asked to be forgotten should not remain in a table under another status.

  • Free edition: the link removes that one signup — the email says it was about one product.
  • Full edition: the link removes every signup for that address on the store, as the email's "remove yourself from every list on this store" promises.

Worked example

A shop sells a kettle that is out of stock. Over a week, 12 shoppers sign up; 9 confirm. On Monday the shop imports a delivery, and the import sets the kettle's stock three times in one request.

  • The first stock event schedules a sweep for 10:01. The other two find it already scheduled.
  • At 10:01 a visitor loads a page, cron runs the sweep, stock is 40.
  • The 9 confirmed rows are claimed and emailed. The 3 pending ones are not — they never confirmed.
  • On Tuesday the warehouse corrects the stock again. A new sweep runs, but there are no confirmed rows left, so nobody hears about the kettle twice.

What the full edition adds

  • Full edition: your own button text, subject and message; a batch size you choose (1–500); the option to switch off confirmation; the demand report; filters for developers (gmbis_show_form, gmbis_email, gmbis_settings).

Both editions use the same table with the same columns and index, so everyone waiting carries over when you upgrade.

Shopping Cart
Scroll to Top