Automattic\WooCommerce\Internal\Admin

ShippingLabelBannerDisplayRules::order_has_shippable_products()privateWC 1.0

Checks if there's a shippable product in the current order.

Method of the class: ShippingLabelBannerDisplayRules{}

No Hooks.

Return

true|false.

Usage

// private - for code of main (parent) class only
$result = $this->order_has_shippable_products();

ShippingLabelBannerDisplayRules::order_has_shippable_products() code WC 8.7.0

private function order_has_shippable_products() {
	$post = get_post();
	if ( ! $post ) {
		return false;
	}

	$order = wc_get_order( get_post()->ID );

	if ( ! $order ) {
		return false;
	}
	// At this point (no packaging data), only show if there's at least one existing and shippable product.
	foreach ( $order->get_items() as $item ) {
		if ( $item instanceof \WC_Order_Item_Product ) {
			$product = $item->get_product();

			if ( $product && $product->needs_shipping() ) {
				return true;
			}
		}
	}

	return false;
}