Free Shipping Progress Notice
Shows "Add 12.00 more to get free shipping" on the cart and checkout pages, or a success message once the threshold is reached.
Opens WPIDE on
Code
$wpide_free_shipping_notice = function () {
$threshold = 75;
if ( ! function_exists( 'WC' ) || ! WC()->cart || WC()->cart->is_empty() ) {
return;
}
$subtotal = (float) WC()->cart->get_displayed_subtotal();
if ( $subtotal < $threshold ) {
wc_print_notice( sprintf( 'Add %s more to your cart to get free shipping.', wc_price( $threshold - $subtotal ) ), 'notice' );
} else {
wc_print_notice( 'Your order qualifies for free shipping.', 'success' );
}
};
add_action( 'woocommerce_before_cart', $wpide_free_shipping_notice );
add_action( 'woocommerce_before_checkout_form', $wpide_free_shipping_notice, 5 );
Notes
Set $threshold to the minimum amount configured in your Free Shipping method.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.