You can automatically show a message on the Cart page when a customer reaches a specific order value. This is useful for promoting discounts, free gifts, or special offers.
Steps
- Open your theme’s
functions.phpfile. - Add the code below.
- Save the file.
- Add products to your cart and test the message.
Done — customers will see a special offer when their cart reaches the specified amount.
function show_cart_discount_message() {
if ( ! WC()->cart ) {
return;
}
$minimum_amount = 100;
$cart_total = WC()->cart->get_subtotal();
if ( $cart_total >= $minimum_amount ) {
echo '<div class="woocommerce-message">
🎉 Congratulations! You qualify for a special discount.
</div>';
}
}
add_action(
'woocommerce_before_cart',
'show_cart_discount_message'
);