Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

“Spend €12 more for free shipping” in the cart

The cart and checkout show how much more the customer needs to spend to get free shipping, and congratulate them when they get there.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Needs WooCommerce
  • Category WooCommerce
  • Tested with WordPress 7.1, WooCommerce 11.1

Before you switch it on: Set $threshold to the minimum order amount of your free shipping method.

It arrives switched off, even when you install its whole pack with "Switch on after installing".

PHP
<?php

$snipfire_free_shipping_notice = static function () {
	$threshold = 50; // Your free shipping minimum, same as in the shipping zone.
	if ( ! WC()->cart || WC()->cart->is_empty() ) {
		return;
	}
	$total = (float) WC()->cart->get_displayed_subtotal();
	if ( WC()->cart->display_prices_including_tax() ) {
		$total -= (float) WC()->cart->get_discount_tax();
	}
	$total -= (float) WC()->cart->get_discount_total();
	if ( $total >= $threshold ) {
		wc_print_notice( 'You get free shipping!', 'success' );
	} else {
		wc_print_notice( sprintf( 'Spend %s more for free shipping.', wc_price( $threshold - $total ) ), 'notice' );
	}
};
add_action( 'woocommerce_before_cart', $snipfire_free_shipping_notice );
add_action( 'woocommerce_before_checkout_form', $snipfire_free_shipping_notice, 5 );

Good to know

For the classic cart and checkout (the [woocommerce_cart] and [woocommerce_checkout] shortcodes). The block cart and checkout don’t use these hooks. Translate the two messages.

In these packs

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.