“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.
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
$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
- WooCommerce: cart and checkout: Free-shipping progress, coupon links, quantity limits and a cleaner checkout.