WooCommerce PHP Intermediate Requires WooCommerce

Show “Add X More for Free Shipping” in the Cart

Tell shoppers exactly how much more they need to spend to get free shipping, right in the cart and at checkout.

Tested on WordPress 7.1 PHP 8.3 Updated
functions.php 15 lines
add_action( 'woocommerce_before_cart', 'nahnu_free_shipping_notice' );
add_action( 'woocommerce_before_checkout_form', 'nahnu_free_shipping_notice' );

function nahnu_free_shipping_notice(): void {
	$threshold = 75.00; // Match the minimum on your Free shipping method.
	$subtotal  = (float) WC()->cart->get_displayed_subtotal();
	$remaining = $threshold - $subtotal;

	if ( $remaining > 0 ) {
		wc_print_notice(
			sprintf( 'Add %s more to get free shipping.', wc_price( $remaining ) ),
			'notice'
		);
	}
}

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

A free shipping threshold only works if shoppers know how close they are. This snippet shows a notice in the cart and at checkout with the exact amount left to spend.

How it works

The function runs on woocommerce_before_cart and woocommerce_before_checkout_form. It compares the cart subtotal, as displayed to the customer including or excluding tax to match your settings, with your threshold, and prints a standard WooCommerce notice with the difference formatted in your store currency.

Once the cart reaches the threshold the notice disappears.

Things to watch

  • Set $threshold to the same minimum as your Free shipping method under WooCommerce → Settings → Shipping. The snippet doesn’t read it automatically, because each shipping zone can have its own.
  • These hooks belong to the classic cart and checkout. On the block-based Cart, use a Notice or Paragraph block, or a plugin made for the blocks.
  • If you use a multi-currency plugin, make sure the threshold is converted too.

How to test it

Add an item worth less than the threshold to the cart. The notice should show the difference. Add more until you pass it, and the notice should go away.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only