Who doesn’t love FREE stuff?

Offering free shipping is something that might just prompt the user to make that one extra purchase. For small products, the cost increase is minimal at most, and it’s always better to sell more, right?

This snippet will add a notification to the top of the cart page to notify the user of how much more they need to put in the cart in order to qualify for free shipping.

Before you just drop this snippet into place, you’ll need to set up a Free Shipping option in the Woocommerce>Shipping menu.

Here’s how you do that:

  1. Create a shipping zone
  2. Select the zone and click “Add shipping method”
  3. Enter your shipping details.

Screenshot of WooCommerce Shipping Setting

The simple notification snippet

/**
 * @snippet       $$$ remaining to Free Shipping @ WooCommerce Cart
 * @compatible    WooCommerce 3.9
 */

add_action( 'woocommerce_before_cart', 'auro_free_shipping_cart_notice' );
  
function auro_free_shipping_cart_notice() {
  
   $min_amount = 250; //change this to your free shipping threshold
   
   $current = WC()->cart->subtotal;
  
   if ( $current < $min_amount ) {
      $added_text = '<div>Get free shipping if you order ' . wc_price( $min_amount - $current ) . ' more!</div>';
      $return_to = wc_get_page_permalink( 'shop' );
      $notice = sprintf( '<div class="shipping-cart-notice"><a href="%s" class="button wc-forward">%s</a> %s</div>', esc_url( $return_to ), 'Continue Shopping', $added_text );
      wc_print_notice( $notice, 'notice' );
   }
}

Snippet to exclude specific user roles from free shipping

This is the same callback function as above but doesn’t trigger the action if the user is logged in with this user role.

/**
 * @snippet       $$$ remaining to Free Shipping @ WooCommerce Cart
 * @compatible    WooCommerce 3.9
 */

if( is_user_logged_in() ) {
	$user  = wp_get_current_user();
	$roles = ( array ) $user->roles;   

	// don't show the message if logged in as a wholesaler
	if ( !in_array( 'wholesale_customer', $roles ) && ! in_array( 'wholesale_customer_e', $roles ) ) {
		add_action( 'woocommerce_before_cart', 'auro_free_shipping_cart_notice' );
	}
} else {
	add_action( 'woocommerce_before_cart', 'auro_free_shipping_cart_notice' );
}
  
function auro_free_shipping_cart_notice() {
  
   $min_amount = 250; //change this to your free shipping threshold
   
   $current = WC()->cart->subtotal;
  
   if ( $current < $min_amount ) {
      $added_text = '<div>Get free shipping if you order ' . wc_price( $min_amount - $current ) . ' more!</div>';
      $return_to = wc_get_page_permalink( 'shop' );
      $notice = sprintf( '<div class="shipping-cart-notice"><a href="%s" class="button wc-forward">%s</a> %s</div>', esc_url( $return_to ), 'Continue Shopping', $added_text );
      wc_print_notice( $notice, 'notice' );
   }
}