$error = true;
}
+ // Before we create an invoice for this member see if they already have one.
+ // If we find one then delete it.
+ $old_invoice_ids = $this->wpdb->get_results(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+ WHERE paid <> true
+ AND renewal = true
+ AND account = %d",
+ $accountID
+ ),
+ ARRAY_A
+ );
+ if ( isset( $old_invoice_ids ) && $old_invoice_ids ) {
+ foreach ( $old_invoice_ids as $old_invoices ) {
+ if ( $inv_id = filter_var( $old_invoices['id'], FILTER_VALIDATE_INT ) ) {
+ $BillingSupport->removeInvoiceById( $inv_id );
+ }
+ }
+ }
// Create the invoice for this member.
$invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data );
if ( !$invoice_id ) {