The Sticky Add to Cart Bar: Scroll-Triggered DOM Manipulation
The sticky add-to-cart bar doesn't rely on a new database table or custom post type. Instead, it hooks into wp_footer to inject a floating <div> that listens to the scroll event via JavaScript. When the native "Add to Cart" button (typically .single_add_to_cart_button) scrolls out of the viewport, the plugin calculates its offset using getBoundingClientRect() and clones its state, price, variations, stock, into the sticky bar. For variable products, it intercepts the found_variation event to ensure the floating bar reflects the selected attributes before submission.
The plugin avoids layout shifts by reserving space in the DOM with position: fixed and bottom: 0, while CSS transitions handle the slide-in/out animation. All logic runs client-side, so there's no server-side overhead beyond the initial asset load. The settings panel, built with the WordPress Customizer API, lets you toggle visibility per device type (mobile-only by default) and sync colors with your theme's wp_theme_json data.
The Free Shipping Bar: AJAX-Powered Cart State Sync
Unlike static banners that query the cart once per page load, the free shipping bar uses WooCommerce's wc_cart_fragments AJAX endpoint to poll for updates every 500ms. When a user adds an item, the plugin recalculates the progress toward the threshold by comparing WC()->cart->subtotal against the stored threshold (saved as a WordPress option via update_option).
For multi-zone shipping, the plugin extends WC_Shipping_Zones to fetch zone-specific thresholds via woocommerce_package_rates. The progress bar's HTML is injected into woocommerce_before_add_to_cart_form or woocommerce_before_cart via PHP filters, while the real-time updates rely on a minimal JavaScript listener that patches the DOM without full-page reloads. The auto-apply logic hooks into woocommerce_cart_shipping_packages to enable free shipping automatically when the threshold is met.
Why This Architecture Works for Developers
Both plugins avoid the pitfalls of heavyweight solutions:
-
No new database tables: They store settings in
wp_optionsand leverage existing WooCommerce hooks. - Minimal JavaScript: The sticky bar uses ~2KB of vanilla JS; the shipping bar's AJAX calls are batched to reduce requests.
-
Theme-agnostic: They target standard WooCommerce classes (
product-type-variable,cart-subtotal) rather than theme-specific selectors.
The combined effect is a 10 - 15% reduction in mobile bounce rates (per internal NEXU WP benchmarks) with zero impact on Core Web Vitals. For stores running headless setups, the plugins' REST API compatibility ensures they work alongside React or Vue frontends.
To implement both, install via the WordPress plugin directory, configure thresholds in the admin panel, and verify the AJAX responses in your browser's Network tab. The entire setup takes less time than debugging a misconfigured wp_query loop, and the conversion uplift starts with the next visitor.
Top comments (0)