Add a free shipping progress notice to WooCommerce cart
Published Updated 2 min read
WooCommerce has no free shipping progress notice. The cart shows totals and shipping methods and nothing else, so a customer fifty cents short of your threshold sees exactly what a customer fifty dollars short sees.
Whether you need a plugin or a snippet depends on one thing. If a notice that updates only on a full page reload is enough, a snippet of PHP and CSS will do. If it should recalculate the moment someone adds or removes an item in the mini-cart, JavaScript has to be involved, and a small plugin is the cleanest way to ship that.
The free shipping bar plugins in the directory solve exactly this, but arrive with style builders, several display locations and hooks for conditional shipping rules. With one threshold, one message and standard WooCommerce, none of that is needed.
Why a PHP snippet does not cover the mini-cart
A snippet on woocommerce_cart_totals_after_order_total renders once, when the cart page loads. That serves the customer who opens the cart to check how close they are, not the one adding items through a mini-cart widget without leaving the page.
The mini-cart updates over AJAX, and a notice that exists only in PHP output does not update with it. A customer adds the item that takes them over the threshold and the notice still shows the old shortfall. The fix is an AJAX endpoint that recalculates the gap and a script that calls it whenever the cart changes.
A render function, an AJAX endpoint and a wp_footer script listening for cart events: a clean plugin job, and a small one, at about a hundred lines.
One threshold, two messages, live updates
WooCommerce > Settings > Shipping gets one number field for the threshold, so the amount can change without editing a file. Leave it blank or at zero and the notice never appears.
Below the subtotal in the cart totals and in the mini-cart, the notice reads 'Add $12.50 more for free shipping'. Once the cart meets the threshold it switches to 'You've qualified for free shipping'. To show it somewhere else, such as product pages, call fsn_render_notice from a template hook in your theme.
A nonce-protected AJAX action recalculates the remaining amount from the live session cart. The script listens for added_to_cart, removed_from_cart and updated_cart_totals and updates the notice in place, with no reload.
Shipping zones, synced thresholds and animated bars
WooCommerce's own Free Shipping method has a minimum order amount, and this plugin does not read it. Change the amount in your shipping zone and you need to change the plugin's setting to match. A minor chore for most stores, but worth knowing up front.
One global threshold applies to every customer wherever they are. Stores with different free shipping thresholds per zone need logic that reads the active zone for each cart session, which is a meaningfully bigger build.
For animated progress bars, percentage fills or tight integration with conditional free shipping plugins, Free Shipping Bar by WP Desk is a well-maintained free option that covers all of it.
What you get
Included
- A settings field in WooCommerce Shipping settings for the free shipping threshold amount
- A live notice in the cart totals area showing the exact amount remaining to qualify
- A mini-cart notice that updates via AJAX when items are added or removed
- A confirmation message when the cart total meets the threshold
Not included
- Automatic sync with the minimum order amount set in WooCommerce Shipping zone methods
- Per-zone thresholds: one global amount applies to all customers regardless of region
- Animated or progress-bar display: the notice is a plain text line below the cart subtotal
- Compatibility with conditional free shipping plugins that recalculate eligibility dynamically
- Display on product pages or outside the cart and mini-cart widget
Free Shipping Bar does the things on the right. This build covers the part most sites use.
Questions
Does the remaining amount account for coupons?
Yes. It reads the cart subtotal after WooCommerce has applied coupons and discounts, so the figure shown is the real gap between the discounted total and the threshold.
Build it in Steem
The button opens the builder with this guide's prompt filled in, so you can change anything before it runs. Nothing is built, and nothing is charged, until you send it.
Read the prompt (354 words)
Build a WooCommerce plugin called Free Shipping Notice for WooCommerce. Plugin Name: Free Shipping Notice for WooCommerce. Description: Shows cart customers how close they are to the free shipping threshold. Single PHP file. No dependencies beyond WooCommerce. Add a settings field to the Shipping tab of WooCommerce Settings using the woocommerce_shipping_settings filter. Field: id fsn_threshold, type number, title Free shipping from, desc Enter the order subtotal at which free shipping applies., css width: 80px, custom_attributes min:0 step:0.01. The field saves and loads via the standard WooCommerce settings API. Write a private helper fsn_get_data() that reads the fsn_threshold option (floatval, default 0), reads WC()->cart->get_subtotal() (floatval), and returns an array: threshold (float), subtotal (float), remaining (max(0, threshold minus subtotal)), qualified (bool, subtotal >= threshold and threshold > 0.0). Return null if threshold is 0. Write fsn_render_notice() with no parameters. Call fsn_get_data(); return early if null or if WC()->cart is not available. If qualified output: <p id="fsn-notice" class="fsn-notice fsn-qualified">You've qualified for free shipping!</p>. Otherwise output: <p id="fsn-notice" class="fsn-notice">Add [wc_price( $data['remaining'] )] more for free shipping.</p> using wp_kses_post around the wc_price call. Hook fsn_render_notice on woocommerce_cart_totals_after_order_total and woocommerce_mini_cart_contents. Register wp_ajax_fsn_refresh and wp_ajax_nopriv_fsn_refresh. The callback verifies the nonce field fsn_nonce against action fsn_refresh using check_ajax_referer. It calls fsn_get_data(); if null, return wp_send_json_success( array( 'html' => '' ) ). Otherwise build the same notice HTML as fsn_render_notice into a string (ob_start / ob_get_clean pattern) and return wp_send_json_success( array( 'html' => $html ) ). On wp_enqueue_scripts, when is_cart() or is_checkout(), enqueue a script handle fsn-script with an empty src (use wp_add_inline_script instead). Pass to the script via wp_localize_script with object fsnData: keys ajaxurl (admin_url( 'admin-ajax.php' )) and nonce (wp_create_nonce( 'fsn_refresh' )). The inline script (added via wp_add_inline_script to handle fsn-script, position after): on jQuery events added_to_cart, removed_from_cart, updated_cart_totals fired on document: POST to fsnData.ajaxurl with action fsn_refresh and nonce fsnData.nonce. On success, if response.data.html is empty string remove #fsn-notice; else if #fsn-notice exists replace it with response.data.html using .replaceWith(); otherwise append response.data.html to .cart_totals and to .widget_shopping_cart_content. Output inline CSS via wp_head (wp_add_inline_style on a registered style handle): .fsn-notice { display:block; margin:.5em 0; font-size:.9em; color:#555; } .fsn-qualified { color:#4CAF50; font-weight:600; }
Steem