Last active
October 27, 2017 11:12
-
-
Save vanbo/817a959c8c0c4cae3bc09d3e3532ce13 to your computer and use it in GitHub Desktop.
WooCommerce: Allow Free Shipping up to Certain Amount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'prefix_is_available_up_to_max_amount', 10, 3 ); | |
/** | |
* @param bool $is_available | |
* @param array $package Shipping package. | |
* @param WC_Shipping_Free_Shipping $shipping_class | |
* @return bool | |
*/ | |
function prefix_is_available_up_to_max_amount( $is_available, $package, $shipping_class ) { | |
$max_amount = 200; | |
$total = WC()->cart->get_displayed_subtotal(); | |
if ( 'incl' === WC()->cart->tax_display_cart ) { | |
$total = round( $total - ( WC()->cart->get_discount_total() + WC()->cart->get_discount_tax() ), wc_get_price_decimals() ); | |
} else { | |
$total = round( $total - WC()->cart->get_discount_total(), wc_get_price_decimals() ); | |
} | |
if ( $total >= $max_amount ) { | |
$is_available = false; | |
} | |
return $is_available; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment