WC_Abstract_Order::needs_shipping
Returns true if the order contains items that need shipping.
Method of the class: WC_Abstract_Order{}
Hooks from the method
Returns
true|false.
Usage
$WC_Abstract_Order = new WC_Abstract_Order(); $WC_Abstract_Order->needs_shipping();
Changelog
| Since 9.9.0 | Introduced. |
WC_Abstract_Order::needs_shipping() WC Abstract Order::needs shipping code WC 10.3.6
public function needs_shipping() {
if ( ! wc_shipping_enabled() || 0 === wc_get_shipping_method_count( true ) ) {
return false;
}
$needs_shipping = false;
foreach ( $this->get_items() as $item ) {
if ( ! is_a( $item, 'WC_Order_Item_Product' ) ) {
continue;
}
$product = $item->get_product();
if ( is_a( $product, 'WC_Product' ) && $product->needs_shipping() ) {
$needs_shipping = true;
break;
}
}
/**
* Filter to modify the needs shipping value for a given order.
*
* @since 9.9.0
*
* @param bool $needs_shipping The value originally calculated.
* @param WC_Abstract_Order $order The order for which the value is calculated.
*/
return apply_filters( 'woocommerce_order_needs_shipping', $needs_shipping, $this );
}