ID, 'apollo_invoice_id', true); $invoice_number = get_post_meta( $order->ID, 'apollo_invoice_number', true); $pdf_invoice_path = APOLLO_DOCUMENTS_DIR."/invoice - ".$invoice_number.".pdf"; $auto_estimate = (bool) get_option('apollo_general_settings')['apollo_send-estimate']; $estimate_number = get_post_meta( $order->ID, 'apollo_estimate_number', true); $estimate_id = get_post_meta( $order->ID, 'apollo_estimate_id', true); $pdf_estimate_path = APOLLO_DOCUMENTS_DIR."/estimate - ".$estimate_number.".pdf"; if ($auto_estimate && $payment_method === 'bacs' && $status !== 'customer_invoice') { // new order; bank transfer $estimate = Apollo_invoice::create($order->ID, 'estimate'); $attachments[] = Apollo_invoice::getPdf($estimate['id'], $estimate['number'], 'estimate'); update_post_meta( $order->ID, 'apollo_estimate_sent', true ); } else if ($auto_invoice && $auto_invoice_status === $status) { // new order; status matches invoice settings $invoice = Apollo_invoice::create($order->ID, 'invoice'); $attachments[] = Apollo_invoice::getPdf($invoice['id'], $invoice['number'], 'invoice'); update_post_meta( $order->ID, 'apollo_invoice_sent', true ); } else if($invoice_id && $status === 'customer_invoice') { // sent maunally from order (invoice) if(file_exists($pdf_invoice_path)) { $attachments[] = $pdf_invoice_path; } else { $attachments[] = Apollo_invoice::getPdf($invoice_id, $invoice_number, 'invoice'); } update_post_meta( $order->ID, 'apollo_invoice_sent', true ); } else if($estimate_id && $status === 'customer_invoice') { // sent maunally from order (estimate) if(file_exists($pdf_estimate_path)) { $attachments[] = $pdf_estimate_path; } else { $attachments[] = Apollo_invoice::getPdf($estimate_id, $estimate_number, 'estimate'); } update_post_meta( $order->ID, 'apollo_estimate_sent', true ); } return $attachments; }