WC_Cart::needs_shipping
Looks through the cart to see if shipping is actually required.
Method of the class: WC_Cart{}
Hooks from the method
Returns
true|false. whether or not the cart needs shipping
Usage
$WC_Cart = new WC_Cart(); $WC_Cart->needs_shipping();
WC_Cart::needs_shipping() WC Cart::needs shipping code WC 10.6.2
public function needs_shipping() {
if ( ! wc_shipping_enabled() || 0 === wc_get_shipping_method_count( true ) ) {
return false;
}
$needs_shipping = false;
foreach ( $this->get_cart_contents() as $values ) {
if ( $values['data']->needs_shipping() ) {
$needs_shipping = true;
break;
}
}
return apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping );
}