Three rules govern the plugin, in both editions.
Rule 1: the bar has no add-to-cart of its own
Many sticky-bar plugins add the product themselves, by sending ?add-to-cart=123 behind the shopper's back. That adds the wrong thing the moment a product has options: no variation, no add-on fields, the wrong quantity, and none of the checks other plugins put on the form.
This plugin does the opposite.
- On the server, the bar's button is printed with
form="gmsacf-product-form"(free) orform="gmsac-product-form"(full) — an HTML attribute that ties a button to a form anywhere on the page. - In the browser, the script finds the page's real add-to-cart form (
form.cart) and gives it that id. - From then on, pressing the bar's button submits the real form. The chosen variation, the quantity, add-on fields, subscription options and every other plugin's validation are part of the submission, because they are the same form. Ajax add-to-cart behaves the way your theme set it up.
On a simple product the page's own button is what tells WooCommerce which product to add (name="add-to-cart", the product's id), so the bar's button carries the same pair. A variable product's form carries it in a hidden field already.
If the script finds no add-to-cart form on the page, it removes the bar. A button that cannot add anything should not be shown.
Full edition: the bar's quantity field is a remote control for the page's own quantity box. It writes into the real field and listens to it, so the form stays the one source of truth.
Rule 2: the bar appears from where the form actually is
Instead of a scroll position in pixels — a guess about one theme that is wrong on the next — the script watches the real form with an IntersectionObserver:
- While any part of the form is on screen, the bar is hidden.
- When the form is entirely off screen, above or below, the bar shows.
So on a layout where the form starts below the visible part of the page, the bar is visible from the start and hides as the shopper reaches the form. On an old browser without IntersectionObserver the bar is simply shown.
The bar is printed into the page footer (wp_footer), not inside the product markup. A fixed bar inside a theme's product wrapper would inherit that wrapper's transforms and overflow and could be clipped.
Rule 3: no bar where it could not do its job
The server decides whether a page gets a bar at all. All of these must be true:
- The plugin's Show the sticky bar on product pages is on.
- The page is a single product page.
- The product is purchasable (published, with a price).
- The product is in stock.
- It is not an external/affiliate product and not a grouped product.
- Full edition: the
gmsac_enabledfilter has not returnedfalsefor this product.
If any fails, there is no bar, and neither the stylesheet nor the script is loaded on that page.
Variable products
A variable product's bar starts with its button disabled, because nothing is chosen yet and the real form would refuse the add.
The script listens to WooCommerce's own variation events on the form:
- A variation is found (
found_variation): the button is enabled if that variation is purchasable and in stock; the bar's price shows the variation's price; in the full edition the thumbnail shows the variation's image. - The choice is cleared (
reset_data,hide_variation): the button is disabled again.
These events come from WooCommerce's variation script, which uses jQuery. On a site where jQuery is not loaded the bar cannot hear them, so it leaves the button enabled and lets the real form decide.
The plugin never works out which variation is chosen by itself.
What the bar shows
| Free edition | Full edition | |
|---|---|---|
| Product name | Yes | Yes |
| Price | Setting, on by default | Setting, on by default |
| Image | — | The product's image, on by default |
| Quantity box | — | A quantity field, off by default |
| Button text | The product's own | Your own, or the product's own |
| Position | Bottom | Bottom or top |
| Screens | All | All, small only or large only |
The button text defaults to the product's own add-to-cart text (single_add_to_cart_text()), so a pre-order or a "Select options" product says the same on the bar as on the page.
Caching
Nothing about the bar depends on the visitor. It is part of the page HTML, hidden until the script reveals it, and the full edition's screen-size choice is a CSS class with a media query. A page cache can serve the same page to everybody.
Colours and dark mode
The bar uses CSS custom properties (--gmsacf-bg, --gmsacf-fg in the free edition, --gmsac-bg, --gmsac-fg in the full edition) with a light default and a dark variant under prefers-color-scheme: dark. The developer reference shows how to override them.
