How to Add a Sticky Add to Cart Bar in WooCommerce Without a Plugin
A WooCommerce sticky add to cart bar keeps the price and the buy button permanently in view while shoppers scroll through descriptions, galleries, tabs and reviews. On mobile, where the real add to cart button disappears after two swipes, that single UI element often does more for conversions than a redesign of the whole product page. Most articles on this topic end with the same advice: install a plugin. This tutorial does the opposite. You will build the bar yourself in a child theme with about 60 lines of PHP, a small CSS file and a lightweight JavaScript scroll listener. No extra plugin, no bloated settings panel, no render-blocking assets, and full control over what the bar shows. What you are going to build A fixed bar that slides in only after the original add to cart form scrolls out of view. Product thumbnail, truncated product name, live price and one clear call to action. Variable product support: the price updates when a variation is selected, and the button switches from Choose options to Add to cart. Zero cumulative layout shift, correct behaviour inside the iPhone safe area, and 44px tap targets. Compatibility with both classic themes and block-based (FSE) product templates. Files you will create in your child theme functions.php (add the two snippets below) assets/css/sticky-atc.css assets/js/sticky-atc.js Plugin or custom code: which one should you pick? Plugins such as Sticky Cart for WooCommerce, Simple Sticky Add To Cart or the various builder add-ons are fine if you want a five minute setup. They are not fine if you care about page weight and Core Web Vitals on product pages. Here is an honest comparison. Criteria Custom code (this tutorial) Sticky add to cart plugin Extra front-end weight About 2 KB CSS + 2 KB JS, product pages only Often 20 to 150 KB, sometimes loaded site-wide Control over markup Total, you own every element Limited to the options exposed Layout shift risk None, the bar is server rendered and animated with transform Common, many inject the bar with JS after load Setup time 20 to 30 minutes 5 minutes Maintenance You maintain it, it never breaks on plugin updates Vendor dependent, can break after WooCommerce updates Cost Free Free to around 79 USD per year Rule of thumb: if your store is above 1,000 sessions a day, the custom version pays for itself in Core Web Vitals alone. Before you start An active child theme. Never edit a parent theme, your changes will be wiped on the next update. FTP, SFTP or the file manager of your host. The theme file editor works too, but a backup first is mandatory. A staging copy if the store is live. WooCommerce with jQuery available (WooCommerce still loads it on product pages, and we use it only for variation events). Step 1: Enqueue the CSS and JS on product pages only Add this to the bottom of your child theme functions.php. The conditional check means the assets never touch your home page, your blog or your checkout. /** * Load sticky add to cart assets on single product pages only. */ add_action( ‘wp_enqueue_scripts’, ‘exp_sticky_atc_assets’ ); function exp_sticky_atc_assets() { if ( ! function_exists( ‘is_product’ ) || ! is_product() ) { return; } wp_enqueue_style( ‘exp-sticky-atc’, get_stylesheet_directory_uri() . ‘/assets/css/sticky-atc.css’, array(), ‘1.0.0’ ); wp_enqueue_script( ‘exp-sticky-atc’, get_stylesheet_directory_uri() . ‘/assets/js/sticky-atc.js’, array( ‘jquery’ ), ‘1.0.0’, true ); } Step 2: Output the bar with a hook Many tutorials hook into woocommerce_after_single_product. That hook does not fire on block-based product templates, which more and more stores now use. Hooking wp_footer with an is_product() check works everywhere, classic or FSE, and it keeps the bar at the end of the DOM where a fixed element belongs. /** * Render the sticky add to cart bar in the footer of single product pages. */ add_action( ‘wp_footer’, ‘exp_sticky_atc_bar’, 20 ); function exp_sticky_atc_bar() { if ( ! function_exists( ‘is_product’ ) || ! is_product() ) { return; } global $product; if ( ! is_a( $product, ‘WC_Product’ ) ) { $product = wc_get_product( get_the_ID() ); } // Skip products nobody can buy from the bar. if ( ! $product || ! $product->is_purchasable() || ! $product->is_in_stock() ) { return; } $is_variable = $product->is_type( ‘variable’ ); $add_text = $product->single_add_to_cart_text(); $options_text = __( ‘Choose options’, ‘child-theme’ ); $price_html = $product->get_price_html(); $image = $product->get_image( ‘woocommerce_gallery_thumbnail’, array( ‘loading’ => ‘eager’, ‘width’ => 48, ‘height’ => 48, ‘alt’ => ”, ) ); ?> <div id=”exp-sticky-atc” class=”exp-sticky-atc” aria-hidden=”true” data-add-text=”<?php echo esc_attr( $add_text ); ?>” data-options-text=”<?php echo esc_attr( $options_text ); ?>” data-default-price=”<?php echo esc_attr( $price_html ); ?>”> <div class=”exp-sticky-atc__inner”> <div class=”exp-sticky-atc__media” aria-hidden=”true”> <?php echo $image; // phpcs:ignore WordPress.Security.EscapeOutput ?> </div> <div class=”exp-sticky-atc__info”> <span class=”exp-sticky-atc__title”><?php echo esc_html( $product->get_name() ); ?></span> <span class=”exp-sticky-atc__price”><?php echo wp_kses_post( $price_html ); ?></span> </div> <button type=”button” class=”button exp-sticky-atc__button” data-product-id=”<?php echo esc_attr( $product->get_id() ); ?>” <?php echo $is_variable ? ‘data-needs-options=”1″‘ : ”; ?>> <?php echo esc_html( $is_variable ? $options_text : $add_text ); ?> </button> </div> </div> <?php } Because the bar is printed by PHP, it exists in the HTML the browser receives. That is the first half of the no-layout-shift strategy: nothing is injected after load. Step 3: The CSS (mobile-first, safe area aware) Create assets/css/sticky-atc.css in your child theme and paste the following. :root { –exp-atc-height: 64px; –exp-atc-offset: 0px; /* raise the bar if you have a chat widget */ } /* Reserve the space at CSS parse time so the footer is never hidden and nothing moves after load. */ @media (max-width: 991px) { body.single-product { padding-bottom: calc(var(–exp-atc-height) + env(safe-area-inset-bottom, 0px)); } } .exp-sticky-atc { position: fixed; left: 0; right: 0; bottom: var(–exp-atc-offset); z-index: 9990; background: #fff; border-top: 1px solid #e5e7eb; box-shadow: 0 -2px 14px rgba(0, 0, 0, .08); padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)); transform: translateY(110%); transition: transform .22s ease; will-change: transform; pointer-events: none; contain: layout paint; } .exp-sticky-atc.is-visible { transform: translateY(0); pointer-events: auto; } .exp-sticky-atc__inner { display: flex; align-items: center; gap: 10px; max-width: 1200px; margin: 0 auto; min-height: 48px; } .exp-sticky-atc__media img { display: block; width: 48px; height: 48px; object-fit: cover; border-radius: 6px; } .exp-sticky-atc__info
How to Add a Sticky Add to Cart Bar in WooCommerce Without a Plugin Read More »









