WC_Meta_Box_Order_Data::order_has_only_virtual_products
Whether every resolvable product line on an order is currently virtual.
This check is used only when no persisted shipping method provides historical fulfillment evidence. It intentionally reflects current, filterable catalog semantics, so product edits can change the summary for no-line orders. Empty or unresolved product sets remain visible because suppressing their persisted shipping details would be ambiguous.
Reading live catalog state is a deliberate, bounded departure from PR #66488's principle that suppression should rest on order-time evidence immune to later catalog edits. This fallback runs only for orders with no persisted shipping line (guaranteed by order_has_no_shipping() earlier in the gate's && chain), which is exactly the population that carries no such order-time evidence, so the catalog read is the only available signal and can never override a persisted shipping line. The accepted tradeoff: reclassifying a product as virtual can later re-hide a no-line order that genuinely shipped. That recurrence is display-only, admin-only, filterable, and pinned as intended by test_hides_shipping_details_after_physical_product_without_shipping_line_becomes_virtual().
The aggregation and fallback here are deliberately local rather than reusing WC_Order::needs_shipping() or the shipping-label helpers: needs_shipping() short-circuits on the global shipping setting and, like those helpers, does not default unresolved or product-less orders to the conservative "keep visible" outcome this summary requires.
Method of the class: WC_Meta_Box_Order_Data{}
No Hooks.
Returns
bool.
Usage
$result = WC_Meta_Box_Order_Data::order_has_only_virtual_products( $order );
- $order(WC_Order) (required)
- Order object.
WC_Meta_Box_Order_Data::order_has_only_virtual_products() WC Meta Box Order Data::order has only virtual products code WC 11.1.2
private static function order_has_only_virtual_products( $order ) {
$items = $order->get_items();
if ( empty( $items ) ) {
return false;
}
foreach ( $items as $item ) {
if ( ! $item instanceof WC_Order_Item_Product ) {
return false;
}
$product = $item->get_product();
if ( ! $product instanceof WC_Product || $product->needs_shipping() ) {
return false;
}
}
return true;
}