Skip to content

Instantly share code, notes, and snippets.

@ventouris
Created April 14, 2018 08:48
Show Gist options
  • Save ventouris/1dc447bc59646ee42bb4b2e005edbf00 to your computer and use it in GitHub Desktop.
Save ventouris/1dc447bc59646ee42bb4b2e005edbf00 to your computer and use it in GitHub Desktop.
Free Shipping message for Woocommerce
function free_shipping_cart_notice() {
$min_amount = 100;
// Subtotal inc. Tax excl. Shipping
$current = WC()->cart->subtotal;
if ( $current < $min_amount ) {
$added_text = esc_html__('You will have FREE shipping if you add ', 'woocommerce' ) . wc_price( $min_amount - $current ) . esc_html__(' more in your order!', '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' );
} else {
wc_print_notice( 'Congrats! You have free shipping with more than 100€ in your order', 'notice' );
}
}
add_action( 'woocommerce_before_cart', 'free_shipping_cart_notice' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment