How Gatemi Side Cart Works

The side cart is one block of markup — the overlay, the panel, the items and the floating button — drawn on the server and placed at the end of every page. Two rules keep it honest.

The flow, step by step

  1. A page loads. Unless it is the cart or checkout page, the plugin prints the side cart in the page footer, closed, with its stylesheet and one small script.
  2. A shopper adds a product from a shop page. WooCommerce's own AJAX add-to-cart runs and returns its cart fragments; the plugin has added its panel to them, so the panel is replaced with an up-to-date copy. If Open automatically when a product is added to the cart is on, the panel slides open.
  3. The shopper changes a quantity with +, − or the box, or presses ×. The script sends the change to the plugin's own endpoint on WooCommerce's frontend AJAX channel (wc-ajax). The endpoint checks a nonce, changes the cart through WooCommerce's cart API, and answers with the same fragments. The panel is replaced again.
  4. Full edition: a coupon typed into the panel is applied the same way, and the free-shipping meter is redrawn with the panel.
  5. The shopper closes the panel with Escape, the close button or the overlay, or goes to the cart or checkout.

Rule 1 — one renderer, one markup path

There is exactly one function that draws the side cart. The first page load, every fragment refresh and every endpoint answer all come from it. There is no second version built in JavaScript that could drift from the server's, so the panel can never show something different from what the next page load will show.

Whether the panel is open is stored as a class on the page's <body> (gmsdcf-open in the free edition, gmsdc-open in the full edition), not inside the panel. That is why replacing the panel during a refresh never slams it shut in the shopper's face. Every click is handled from the document, so a replaced panel never loses its buttons.

Changing the cart

  • A quantity is set with WooCommerce's own set_quantity(). A quantity of 0 removes the line, exactly as the cart page treats it. A new quantity is first put to the same checks the cart page makes: a product sold individually stays at one, and a quantity another plugin refuses through woocommerce_update_cart_validation is not set.
  • Remove uses WooCommerce's own remove_cart_item().
  • Both endpoints refuse a request without a valid nonce.
  • Because the cart's own API is used, everything else that watches the cart — stock checks, minimum and maximum quantities, other plugins — still has its say.

Standing aside on the cart and checkout

On WooCommerce's cart and checkout pages nothing is printed and nothing is loaded. Those pages already are the cart, and a second cart sliding over the checkout only gets in the way.

Full edition: the free-shipping meter

Never invent a number the store did not configure. The meter reads the Free shipping method in the shipping zone that matches the cart — found with WooCommerce's own zone matching, not a copy of it — and measures the cart the way WooCommerce's Free shipping method itself decides whether it applies:

  • the displayed subtotal;
  • minus discounts — and their tax, on a store that shows prices including tax — unless the method has Apply minimum order rule before coupon discount ticked, in which case neither comes off.

The meter shows only for a rule a cart amount can satisfy: A minimum order amount, or A minimum order amount OR a coupon. A rule that needs a coupon, or a coupon and a minimum, cannot be reduced to one number, so it gets no meter rather than a wrong one — and nor does a rule with no requirement (N/A), because WooCommerce gives that free shipping to every cart. A zone with no Free shipping method gets no meter either.

Worked example. Free shipping in the UK zone needs a £50 minimum. A UK shopper has £37.50 in the cart: the panel reads "Add £12.50 more to unlock free shipping" with the bar three-quarters full. They add a £15 item, the panel refreshes, and it reads "You have unlocked free shipping!".

Full edition: the coupon field

A code typed into the panel is applied with WooCommerce's own apply_coupon(), so every restriction on the coupon is checked by WooCommerce. The panel shows its own message and WooCommerce's queued notice is cleared, so the shopper is not told twice on the next page.

Full edition: the accent colour

The colour is passed to the panel as a CSS custom property on its root element (--gmsdc-accent), not as a separate stylesheet, so a fragment refresh carries it along.

Next: FAQ and troubleshooting.

Shopping Cart
Scroll to Top