/** * Returns a modified line item tree where all the subtotals which have a total of 0 * are removed, and line items with a quantity of 0 * * @param EE_Line_Item $line_item |null * @return \EE_Line_Item|null */ public static function non_empty_line_items(EE_Line_Item $line_item) { $copied_li = EEH_Line_Item::non_empty_line_item($line_item); if ($copied_li === null) { return null; } //if this is an event subtotal, we want to only include it if it //has a non-zero total and at least one ticket line item child $ticket_children = 0; foreach ($line_item->children() as $child_li) { $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); if ($child_li_copy !== null) { $copied_li->add_child_line_item($child_li_copy); if ($child_li_copy->type() === EEM_Line_Item::type_line_item && $child_li_copy->OBJ_type() === 'Ticket') { $ticket_children++; } } } //if this is an event subtotal with NO ticket children //we basically want to ignore it if ($line_item->type() === EEM_Line_Item::type_sub_total && $line_item->OBJ_type() === 'Event' && $ticket_children === 0 && $line_item->total() === 0) { return null; } return $copied_li; }