WC_Shipping_Free_Shipping::is_available( array $package )
See if free shipping is available based on the package and cart.
Description Description
Parameters Parameters
- $package
-
(Required) Shipping package.
Return Return
(bool)
Source Source
File: includes/shipping/free-shipping/class-wc-shipping-free-shipping.php
public function is_available( $package ) {
$has_coupon = false;
$has_met_min_amount = false;
if ( in_array( $this->requires, array( 'coupon', 'either', 'both' ), true ) ) {
$coupons = WC()->cart->get_coupons();
if ( $coupons ) {
foreach ( $coupons as $code => $coupon ) {
if ( $coupon->is_valid() && $coupon->get_free_shipping() ) {
$has_coupon = true;
break;
}
}
}
}
if ( in_array( $this->requires, array( 'min_amount', 'either', 'both' ), true ) ) {
$total = WC()->cart->get_displayed_subtotal();
if ( WC()->cart->display_prices_including_tax() ) {
$total = $total - WC()->cart->get_discount_tax();
}
if ( 'no' === $this->ignore_discounts ) {
$total = $total - WC()->cart->get_discount_total();
}
$total = round( $total, wc_get_price_decimals() );
if ( $total >= $this->min_amount ) {
$has_met_min_amount = true;
}
}
switch ( $this->requires ) {
case 'min_amount':
$is_available = $has_met_min_amount;
break;
case 'coupon':
$is_available = $has_coupon;
break;
case 'both':
$is_available = $has_met_min_amount && $has_coupon;
break;
case 'either':
$is_available = $has_met_min_amount || $has_coupon;
break;
default:
$is_available = true;
break;
}
return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package, $this );
}