How Gatemi Product Add-Ons Works

The free edition, step by step

  1. On the product page, the options are printed just above the Add to cart button (WooCommerce's woocommerce_before_add_to_cart_button hook), inside the product's own form. A fee shows beside its label.
  2. On add to cart, the plugin reads what was posted for each option. A ticked checkbox is recorded as "Yes"; a text option with something typed is recorded as the text. Unused options are left out.
  3. In the cart, the used options' fees are spread over the line's unit price: the fee is divided by the line's quantity, so the line total carries it exactly once. The unit price is measured from the price it came in at that request, so recalculating the cart several times never compounds the fee, and a changed quantity spreads the same fee afresh.
  4. On the cart line, each choice shows with its fee: "Engraving: Anna (+$5.00)".
  5. On the order, each choice is saved as a line-item meta row named after the option, so it shows in the admin, emails, My Account and exports.

A fee is charged once per line, whatever the quantity: two engraved mugs on one line at a $5 engraving fee add $5, not $10.

The full edition: three rules

1. One resolver, one field engine

One place decides which fields a product has, and one handler per field type both checks what was posted and turns it into cart entries. The product page, add-to-cart, the Store API (Cart and Checkout blocks), order-again and the order screen all ask the same two. A choice the form offered is therefore never refused later with a different answer.

Which fields a product has:

  1. A variation shows its parent's fields first.
  2. Then the product's own fields, at position 10.
  3. Global groups that apply to the product (all products, or its categories — a variation is matched by its parent) are merged in by Display order: below 10 above the product's fields, 10 or more below them.
  4. Use global add-ons off on the product skips step 3.
  5. Fields with no title are dropped.

2. One shape

Everything stored — from the editor, the importer or the JSON paste — goes through one normaliser. A field id is guaranteed, so posted values are matched by id and reordering fields never mixes answers up. Hidden options keep their place, so dropdown values stay stable.

3. Prices are honest

When an item is added, the product's price before add-ons is kept on the cart item. Every recalculation starts again from that snapshot:

  • Per quantity — the price is added to the unit price.
  • Percentage of the price — the percentage of the snapshot is added to the unit price. It is never a percentage of other add-ons, and never applied twice.
  • Flat fee — divided by the line quantity and added to the unit price, so the line total carries the fee exactly once. The unit price shown in the cart has the flat fees taken back out, so it does not look strange. A quantity change re-derives everything from the snapshot.
  • Quantity field — the field's price times the number entered.
  • Customer-defined price — the amount typed, added per unit. A negative amount is refused with a message rather than quietly ignored.

Worked example (full edition)

A €20 T-shirt, quantity 2, with:

  • "Print on back" — per quantity €4;
  • "Gift box" — flat fee €6;
  • "Premium cotton" — 10 % of the price.

Unit price: 20 + 4 + 3 (6 ÷ 2) + 2 (10 % of 20) = €29. Line total: €58, which is €40 + €8 + €6 + €4 — every fee charged exactly as named.

Validation (full edition)

On add to cart, before the item enters the cart:

  • a Required field must be filled in;
  • a posted dropdown or radio value must match one of the field's options — an unknown value is an error, not a silent drop;
  • text length, quantity and price bounds are checked;
  • dates must be real dates;
  • uploads must be within the server's upload size and, when limited, of an allowed extension whose content matches it.

A product with a required field gets Select options instead of Add to cart on shop listings, and its listing link goes to the product page, because it cannot be added without the fields.

Uploads (full edition)

Files are stored under wp-content/uploads/gmpa_uploads/, in a folder per customer, with empty index files so the folders cannot be listed.

The order (full edition)

Each field becomes a visible line-item meta row named after the field. Hidden meta (_gmpa_ids, _gmpa_total) keeps the structured record, so Order again puts the same choices back in the cart.

Express payment buttons (full edition)

On a product with add-ons, the plugin tells Stripe, WooPayments and PayPal express buttons not to show on the product page, because a one-tap wallet payment would skip the fields.

Shopping Cart
Scroll to Top