Three rules govern the plugin.
Rule 1: the conditions are declared once
The list of conditions — on sale, out of stock, chosen products, and in the full edition new, low stock and featured — is defined in one place. The settings screen draws its dropdown from it, the save refuses anything not in it, and the code that decides whether a product wears a badge has exactly one answer per condition. A condition nobody recognises matches nothing, so it never shows a badge on the wrong products.
Rule 2: WooCommerce's own answer
Every automatic condition asks WooCommerce rather than working it out again:
- On sale — WooCommerce's own "is this on sale?" answer, so the badge cannot disagree with the struck-through price beside it, including scheduled sales.
- Out of stock — WooCommerce's own stock status.
- Low stock — Full edition — the product's own low-stock amount, falling back to the store's, the same order WooCommerce uses for its "Only 2 left" notice. A product that does not manage stock is never "low".
- Featured — Full edition — WooCommerce's featured flag (the star on the products list).
- New — Full edition — the day the product was first published compared with Days counted as new, on your store's clock. The plugin records that day the first time a product moves to Published; a product published before the plugin was installed falls back to its creation date.
Chosen products or categories matches a product listed by id (a variation follows its product), or a product in a listed category or any of its sub-categories.
Rule 3: printed, never injected
Badges are printed through the hooks WooCommerce uses for its own sale flash:
| Where | Hook |
|---|---|
| Shop, category and search listings | woocommerce_before_shop_loop_item_title |
| Product page | woocommerce_before_single_product_summary |
Many badge plugins instead rewrite the product image's HTML. That breaks the image's responsive srcset, lazy-loading, and themes that render their own image markup. Printing beside the image avoids all three. The badge is positioned over the image by the plugin's stylesheet.
The flow for one product
- WooCommerce reaches the hook for a product card or product page.
- The plugin goes through the active badges in your order.
- Full edition: a badge outside its start and end dates is skipped.
- Each remaining badge whose condition matches is kept.
- If none match, nothing at all is printed — not even an empty wrapper.
- The kept badges are grouped by corner. Each corner is one stack, in the order you listed the badges, so "why is New above Sale?" has an answer you can change by reordering.
How a badge looks
Full edition: each badge carries its own colours as two CSS custom properties on the badge element (--gmbg-bg, --gmbg-fg), plus a shape class and a corner class. No stylesheet is generated per badge, so six badges do not add six rules to every page.
Free edition: each badge is a plain <span class="gmbgf-badge"> in one stack at the top left. The whole look comes from the plugin's stylesheet, so you can restyle it with your own CSS.
The stylesheet is loaded in the head on WooCommerce pages (shop, categories, products), and anywhere else as soon as a badge is printed — a [products] shortcode or a Product Collection block on any page included.
Badges and the sale flash
WooCommerce prints its own "Sale!" flash on products on sale. A sale badge of your own would then make two. Full edition: Remove WooCommerce's own sale flash removes it from the page — it is taken out, not hidden with CSS, so a screen reader does not announce the sale twice.
Worked example (full edition)
| Badge | Condition | Corner | Order |
|---|---|---|---|
| New | published in the last 14 days | Top left | 1 |
| -20% | chosen category "Spring sale" | Top left | 2 |
| Only a few left | low stock | Top right | 3 |
A product created last week, filed under "Spring sale", with 2 left (store threshold 2): top left shows New above -20%; top right shows Only a few left.
Caching
Whether a product wears a badge is decided when the page is built. With a full-page cache, a badge appears or disappears when the cached page is rebuilt — after a sale starts, stock runs out or a schedule changes. Clear or let the cache refresh to see the change straight away.
