How Gatemi Coupon URLs Works

A coupon link is a convenient way to type a coupon code. It is never a way around what the code says. Three rules hold that together, and both editions follow all three.

Rule 1: WooCommerce applies the coupon, and its answer is the answer

When a link is followed, the plugin calls WooCommerce's own WC()->cart->apply_coupon() with the coupon's code — exactly what happens when a shopper types the code into the cart.

That means every restriction you set on the coupon is checked by WooCommerce, not by this plugin:

  • the expiry date,
  • the usage limit and the per-customer usage limit,
  • the minimum and maximum spend,
  • the products and categories it covers or excludes,
  • the allowed email addresses,
  • Individual use only.

If WooCommerce refuses the coupon, nothing is discounted and the shopper sees WooCommerce's own explanation, in the wording you or WooCommerce gave it. The plugin adds no second message. Some plugins in this category apply the coupon straight to the session instead; that is how an expired campaign keeps discounting for months. This one cannot do that, because it never decides on its own whether a coupon is valid.

If the coupon is already on the cart, the link counts as applied and does not apply it a second time.

When the cart is empty

WooCommerce checks some restrictions — the minimum spend, the products a coupon covers — against the cart as it is at that moment. A coupon with a minimum spend of £50, followed from an empty cart, is refused for that reason. Two ways to deal with that:

  • Give such coupons no minimum, or send the shopper to the shop and let them type the code at the cart.
  • Full edition: list products in Also add to the cart. Products are added after the coupon is applied, so they do not help a minimum-spend check on the same click. A shopper who follows the link a second time, with the products already in the cart, gets the coupon.

A followed link never shows a page of its own. It does its work and sends the shopper on with a redirect (wp_safe_redirect()), to the page you chose in Then send them to.

That matters for three reasons:

  • Refreshing the page does not run the link again and add the products a second time.
  • The address in the shopper's browser is a normal page, so they do not bookmark or share the coupon address with their session attached.
  • A full-page cache never stores the result of a link under the link's own address, because the link's address never returns a page to cache.

The redirect uses wp_safe_redirect(), which only allows addresses on your own site. Full edition: a That page address on another site is not followed; the visitor lands on your home page instead. Keep landing pages on your own domain.

The link address is stored as meta on the coupon (_gmcu_slug), not in a separate table. So WooCommerce's own coupon screen, search, trash and usage limits all apply to it, and deleting a coupon is what removes its link.

To answer a request quickly, the plugin keeps a small index in one option, gmcu_index: every link address and the coupon it belongs to. A storefront request that is not a coupon link costs one cached option read.

The index is rebuilt from the coupons themselves — never patched — when:

  • a coupon's URL tab is saved,
  • a coupon is moved to the trash, restored from it, or deleted permanently.

Only published coupons are put in the index. Two coupons can never share an address: the URL tab refuses an address another coupon already has.

The flow, step by step

  1. A shopper opens https://yourshop.com/coupon/spring-sale/.
  2. WordPress matches the plugin's rewrite rule ^coupon/([^/]+)/?$ and sets the query variable gmcu_link to spring-sale. (The first part follows your Links start with setting.)
  3. On template_redirect — late enough that the cart exists, early enough that nothing has been sent — the plugin looks spring-sale up in the index. Not found: nothing happens, and WordPress carries on with the request as usual.
  4. It reads the coupon. A coupon set back to draft, pending or private leaves the index the moment its status changes, so its link stops answering; if a request still reaches an unpublished coupon, nothing is applied, but the shopper is sent on to the landing page rather than to an error.
  5. It calls apply_coupon() with the coupon's code. WooCommerce applies it or refuses it and adds its own notice.
  6. Full edition: it adds each listed product with WooCommerce's own add_to_cart(), quantity 1. A product that cannot be added — out of stock, not purchasable, a variable product with no variation chosen — is skipped, and the rest still go in. WooCommerce's own add-to-cart checks, and other plugins' checks, all apply.
  7. Full edition: if the coupon was applied and Say so when a link applies a discount is on, it adds your success message.
  8. It redirects to the landing page.

The address

The rewrite rule is a real WordPress rule with its own query variable, so it works with any pretty permalink structure and with WordPress in a subdirectory. With plain permalinks (?p=123), pretty addresses do not exist; the link can still be followed as ?gmcu_link=spring-sale.

The plugin flushes WordPress' rewrite rules once — on the first request after the prefix changes — and never on ordinary requests, because flushing rewrites an option on every page load.

Addresses are refused when they are:

  • already used by another coupon,
  • only digits, such as 2026, because some permalink structures read a number as a post id,
  • empty after WordPress' sanitize_title() — which also turns Spring Sale! into spring-sale.

An emptied Links start with field is saved as coupon, because a rule with no prefix would match every one-word address on the site.

Moving between editions

Both editions read and write the same index, the same meta keys and the same query variable. A link handed out under one keeps working under the other. The free edition leaves the full edition's Also add to the cart and That page values on the coupon untouched and does not use them: a link set to A page of my own lands on the home page in the free edition, and a link with products applies its coupon and adds nothing.

Shopping Cart
Scroll to Top