Show customers how much more they need to spend to qualify for free shipping. This can encourage customers to add another product to their cart.
Steps
- Open your theme’s
functions.phpfile. - Add the code below.
- Save the file.
- Open the WooCommerce Cart page.
Done — a dynamic free-shipping message will appear above the cart.
function add_free_shipping_progress_message() {
$minimum_amount = 100;
if ( ! WC()->cart ) {
return;
}
$cart_total = WC()->cart->get_subtotal();
if ( $cart_total < $minimum_amount ) {
$remaining = $minimum_amount - $cart_total;
echo '<div class="woocommerce-info">
Add ' . wc_price( $remaining ) . ' more to get free shipping!
</div>';
} else {
echo '<div class="woocommerce-message">
🎉 You qualify for free shipping!
</div>';
}
}
add_action(
'woocommerce_before_cart',
'add_free_shipping_progress_message'
);