A simple, powerful and independent e-commerce platform.
Sell anything with ease.

Display extra amount needed for free shipping

If you offer free shipping for more than a certain order value, it can be helpful to show a message in the cart to tell the customer how much more they need to spend to qualify for free shipping.

/**
 * Display extra amount needed for free shipping
 */

add_action('woocommerce_before_cart', 'cc_free_shipping_cart_notice');

function cc_free_shipping_cart_notice() {

  $min_amount = 50; //change this to your free shipping threshold

  $current = WC()->cart->subtotal;

  if ($current < $min_amount) {
    $added_text = esc_html__('Get free shipping if you order another ', 'woocommerce') . wc_price($min_amount - $current) . esc_html__(' more!', 'woocommerce');
    $return_to = apply_filters('woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect(wc_get_raw_referer(), false ) : wc_get_page_permalink('shop'));
    $notice = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url($return_to), esc_html__('Continue Shopping', 'woocommerce'), $added_text);
    wc_print_notice($notice, 'notice');
  }

}
View Raw Code ID: 994