Both editions turn a paid order into coupons. The free edition does it for gift certificates and stops there. The full edition adds store credit that behaves like money, gifting, conditions and the storefront panel.
Issuing a gift certificate (free edition)
- A shopper buys a product with Gift certificate ticked.
- The order reaches Completed. That status change — and only that one — triggers issuing.
- The plugin looks for codes already recorded on the order (order meta
_gmscf_codes). If there are any, it stops. WooCommerce can fire a status change more than once, and a re-fired change must never mint a second set of certificates. - For each gift-certificate line, the value of one unit is the line subtotal divided by the quantity, rounded to two decimals. That is the price actually charged for the item, sale price included, before cart-level coupons and without tax. A unit worth nothing is skipped.
- One coupon is created per unit: a
GIFT-XXXX-XXXX-XXXXcode, fixed cart discount, usage limit 1. If a generated code already exists, another is drawn (up to five tries). - The codes and their values are saved on the order, an order note lists them, and one email "Your gift certificate" goes to the billing address.
The certificate is an ordinary WooCommerce coupon. It keeps working if you deactivate or delete the plugin.
Issuing coupons (full edition)
The full edition works from templates. You configure one coupon — "£25 gift card", "20% off, once" — and link it to a product in Coupons to hand out. The template itself is never handed out and never spent.
- Add to cart. If the product hands out coupons, a gift form is drawn above the add-to-cart button. What the buyer types (recipient email and name, from, a message up to 500 characters, a delivery date, and an amount for a pick-your-price product) is stored as cart item data. That is why the classic checkout, the Checkout block and the Store API all carry it with no per-surface code.
- Order paid. When the order first reaches a status in Issue on, the issuer writes one row per coupon into the outbox table
{prefix}gmsc_issuancebefore creating anything. Itsdedupe_keyis a hash of the order line, the template and the recipient, and it is unique in the database — a replayed status change loses that race rather than issuing a second card. - Stamp the copy. The template is copied field by field (not by duplicating the post, which would carry its usage counts and other plugins' meta). The copy gets its own code, its own expiry from Valid for (days after issue), its own balance and, when recipient restriction applies, an allowed-email list of the recipient's address.
- Deliver. With no delivery date, the Coupon delivery email goes out at once (after the
gmsc_issue_delay, default 0 seconds). With a date, an hourly cron (gmsc_deliver_scheduled) sends it on that day. Each row moves through Pending → Issued → Sent, or to Failed with the reason kept on the row. - Undo. If the buying order is cancelled or refunded, every coupon it issued is moved to the trash and its row marked Revoked.
WooCommerce → Coupon activity lists every issued coupon with its value, recipient, order, status and date, and a Send now / Retry button.
Store credit (full edition)
A coupon of type Store Credit / Gift certificate (gmsc_store_credit) carries a balance that spends a little at a time.
The ledger
The balance lives in coupon meta gmsc_balance, because every cart calculation reads it. That number is only trustworthy because every change to it is written to {prefix}gmsc_credit_ledger first, with the resulting balance alongside: issue, redeem, restore, expire or adjust. A merchant asked "where did this card's money go?" reads the ledger on the coupon's Smart Coupons tab.
Spending it at checkout
Credit is applied in two passes:
- WooCommerce asks the coupon line by line. The plugin draws the balance down against each line and divides the answer back by the quantity.
- Whatever the goods did not use is added as a negative fee, so with Credit covers set to the whole order the card also pays for shipping, fees and tax. The Checkout block and the Store API show negative fees natively.
With the goods only, the second pass does not run.
Charging the card
When the order is paid (payment complete, Processing or Completed), the amount is read back off the order — the coupon line's discount plus its tax, plus the negative fee tagged with that coupon — and never recomputed from the cart. WooCommerce may have clamped a fee, a merchant may have edited the order, a gateway may have settled differently. The order is then marked (_gmsc_credit_redeemed) so a second callback does not charge the card twice.
Giving it back
- Refund: the same proportion of the charge is restored to the card.
- Cancelled or failed: the whole charge is restored.
- Expired: a daily cron writes off the remaining balance of expired credit coupons, with an expire ledger row.
- Retire spent cards on: a card that reaches zero is trashed.
Conditions (full edition)
A coupon's Conditions are extra rules on top of WooCommerce's own usage restrictions, matched with all of these rules or any of these rules. There are 19 condition types:
| Group | Conditions |
|---|---|
| Customer | Customer role, Customer email, Signed in, First order, Orders placed, Lifetime spend |
| Location | Billing country, Billing state / county, Shipping country, Shipping state / county, Shipping postcode |
| Cart | Items in cart, Quantity of a product, Product attribute, Product taxonomy term |
| Checkout | Payment method, Shipping method |
| Timing | Day of week, Hour of day |
A coupon with no conditions is unrestricted. A rule naming a condition the plugin does not know (left by a removed extension) is kept — the coupon screen shows it as "Not recognised" — and a condition with no evaluator counts as not matching, so it can only narrow a coupon, never open it up.
One evaluator decides every condition, for typed codes, links, the panel and automatic coupons alike. There is no second copy of the logic for the panel to disagree with.
The coupon panel (full edition)
On the cart, the checkout and My Account (per Show on), and wherever [gmsc_coupons] is placed, the panel lists the coupons this shopper may use right now:
- Candidates come from an indexed meta lookup: coupons issued to the shopper's address, plus coupons marked Show to everyone — never a scan of every coupon. Coupons marked Never show are left out.
- Each candidate is put through WooCommerce's own
WC_Discountscheck and the conditions, exactly as applying it would be. A coupon the checkout would refuse is not shown. - The list is capped at Most coupons to show.
Every Apply button is a real link first, so it works with JavaScript blocked, and is upgraded to an in-page request when the script loads. On the Cart and Checkout blocks the panel is rendered by the server around the block, not inside the block's own interface.
Automatic coupons and links (full edition)
- A coupon with Apply automatically is tried on every cart calculation and applied when it qualifies. When it stops qualifying — the product that earned it was removed, the total dropped — it is taken off again. The removal is the half that stops a store giving money away.
- With Coupons in links on,
?gmsc-coupon=CODEon any storefront URL stores the code in the session and applies it through the same checks a typed code goes through.
Reminders (full edition)
A daily cron (gmsc_send_reminders) sends the Coupon reminder email for coupons expiring within Remind before expiry days, and for coupons unused Remind about unused coupons days after issue. Each coupon is reminded about once — it records the reminder whatever happens — so a seven-day window does not mean seven emails.
