function wc_gzdp_order_has_invoice_type($order, $type = 'simple')
{
    $found = false;
    $invoices = wc_gzdp_get_invoices_by_order($order);
    if (!empty($invoices)) {
        foreach ($invoices as $invoice) {
            if ($invoice->is_type($type)) {
                $found = true;
            }
        }
    }
    return $found;
}
 function wc_gzdp_invoice_download_html($order_id)
 {
     $order = wc_get_order($order_id);
     global $invoices;
     $invoices = wc_gzdp_get_invoices_by_order($order);
     foreach ($invoices as $key => $invoice) {
         if (!in_array($invoice->type, wc_gzdp_get_invoice_frontend_types())) {
             unset($invoices[$key]);
         }
     }
     $invoices = array_values($invoices);
     if (!empty($invoices)) {
         wc_get_template('invoice/download.php');
     }
 }
 public function add_meta_boxes()
 {
     global $post;
     $order = wc_get_order($post);
     $invoices = wc_gzdp_get_invoices_by_order($order);
     if (!empty($invoices)) {
         foreach ($invoices as $id => $invoice) {
             $theinvoice = $invoice;
             if (!($classname = $this->get_meta_box_class($invoice->type))) {
                 continue;
             }
             add_meta_box('woocommerce-invoice-' . $invoice->id, $invoice->get_title(), $classname . '::output', 'shop_order', 'normal', 'high', array('invoice' => $theinvoice));
             if ($invoice->type == 'simple' && !$invoice->is_cancellation() && !$invoice->is_cancelled()) {
                 $theinvoice = wc_gzdp_get_invoice(false, 'cancellation');
                 $theinvoice->set_parent($invoice->id);
                 // Add new Cancellation
                 add_meta_box('woocommerce-invoice-cancellation-new', sprintf(__('Cancel %s', 'woocommerce-germanized-pro'), $invoice->get_title()), 'WC_GZDP_Meta_Box_Invoice::output', 'shop_order', 'normal', 'high', array('invoice' => $theinvoice));
             }
         }
     }
     foreach (wc_gzdp_get_invoice_types() as $type => $values) {
         if (wc_gzdp_order_has_invoice_type($order, $type)) {
             continue;
         }
         if ($values['manual'] || !($classname = $this->get_meta_box_class($type))) {
             continue;
         }
         $theinvoice = wc_gzdp_get_invoice(false, $type);
         // Add new Invoice
         add_meta_box('woocommerce-invoice-' . $theinvoice->type . '-new', $values['title_new'], $classname . '::output', 'shop_order', 'normal', 'high', array('invoice' => $theinvoice));
     }
 }