Choosing the offer
Each time the checkout (or, in the full edition, the cart page) is drawn, the plugin reads your offers top to bottom and keeps the ones that apply, up to How many to show at once for that place (always one in the free edition).
An offer applies when:
- Show my offers is on and the offer's Offer this one is ticked;
- it is for this place (Shown; the free edition only uses "Just above the pay button");
- its product is not already in the cart. A variation in the cart counts as its parent, so an offer of a T-shirt is not shown to somebody who has the blue one. Offering what somebody already has is the most visible mistake a bump can make, on the page where they are handing over money. The exception is the offer the shopper accepted: it stays on the page, ticked, so they can change their mind;
- every Only when condition holds (Full edition);
- its product still exists, can be bought and is in stock. The shopper would otherwise tick it, WooCommerce would refuse, and the refusal would land on the payment page.
Free edition and the full edition's settings: an offer that carries conditions, or is placed anywhere other than above the pay button, is simply not shown by the free edition. It never evaluates a condition, so an offer meant for a few shoppers is never shown to everybody. An offer priced with a percentage is never charged at a percentage by the free edition.
What the shopper sees
A box with a tick box, the heading, your line, and the price. When the offer is cheaper than the product's normal price, both are shown — the normal price struck through and the offer price beside it — because a price on its own is not an offer.
Rule 1: it goes through WooCommerce's own cart
Ticking the box adds the product with WooCommerce's add_to_cart(), quantity one. That is the same path as an Add to cart button, so stock checks, "sold individually", purchasability and every other plugin's add-to-cart validation apply. A shortcut that writes the line straight into the cart would sell things the shop does not have, at the one moment it is least able to say so.
Accepting twice (a double tap on a slow connection) is still one line. The line carries a marker (gmob_bump) naming the offer it came from.
Rule 2: answering does not cost the shopper what they typed
On the checkout the tick box is part of the checkout form, inside WooCommerce's own update_totals_on_change wrapper, so ticking it starts WooCommerce's checkout refresh (the update_order_review request). Its state travels with that request: a ticked box adds the product, an unticked box removes a line that offer had added. The totals update without a page reload, so nothing the shopper typed is lost.
The shown rule. Each box drawn on the page posts a hidden gmob_shown[] beside it, and only an offer that was shown and left unticked is declined. An offer that was not on the page — another placement, past the cap, a block page — is left as it is, so a refresh never takes an accepted offer back off by accident.
Place order. A tick still on its way when Place order is pressed is taken on woocommerce_checkout_process, before the order is created. If it changed the cart, the order is held back with a notice and the totals are redrawn, so nobody is charged a total they did not see.
Blocks. The Checkout block (and, in the full edition, the Cart block) fires none of these hooks, so the offers are printed above the block, server side, as the same nonce-checked links the no-JavaScript path uses.
On the cart page (Full edition) the offer is a link — Yes, add this or Remove this — with a nonce. In the free edition a shopper without JavaScript gets the same kind of link inside the checkout box.
Rule 3: the discount is a price on the line, not a coupon
A coupon shows in the totals as something the shopper can remove, applies to whatever else it matches, and turns an offer into a code that ends up on a forum. Instead, on every cart calculation (woocommerce_before_calculate_totals, priority 20 — the one the classic cart, the mini-cart and the checkout all go through) the accepted line's price is set to the offer price.
The offer price is always measured from the price the line came in at (stored on the line as gmob_base), never from the line's current price, so recalculating six times does not take the discount off six times.
If you delete an offer after a shopper accepted it, the line stays in their cart — the cart is theirs — and goes back to its ordinary price.
The record
- In the cart and checkout the line shows Added as: followed by the heading (or "a special offer").
- When the order is created, the order line gets the meta
_gmob_bumpholding the offer's heading (or its id), so you can see later why that line is there. Uninstalling never removes it.
Worked example (full edition)
Offer: product 318 "Phone case", heading "Add a matching case", An amount off 5, Shown just above the pay button, Only when "The cart holds something from these categories" 42 (Phones).
- A shopper's cart holds a phone from category 42 and no case. The offer is shown:
£15.00£10.00. - They tick it. The checkout refreshes and the case is added at £10.00, "Added as: Add a matching case"; the box stays, ticked.
- They place the order. The case line is £10.00 and carries
_gmob_bump = Add a matching case. - Another shopper's cart holds only a charger. The condition fails; no offer.
