• Hi WP-Invoice,

    I have just started using your plugin in a project where I have run in to an issue.

    I am trying to programmatically create an invoice. The thing is, that I can get it to save the invoice, so it shows up in the control panel with all credentials, line items etc. correctly. But it does not send the notification e-mail automatically. Why is that? I have attached my current code.

    $invoice = new WPI_Invoice();
    
    // Set defaults
    $invoice->load_defaults();
    
    // Set user
    $user_args = array(
    	'email' => $email,
    );
    
    $invoice->load_user( $user_args );
    
    // Create the invoice
    $invoice_args = array(
    	'subject' => 'Subject title',
    	'description' => 'Description'
    );
    
    $invoice->create_new_invoice( $invoice_args );
    
    // Add a line item
    $line_item_args = array(
    	'name' => 'Some name',
    	'description' => 'Some description',
    	'quantity' => 1,
    	'price' => '2500',
    	'tax_rate' => '25'
    );
    
    $invoice->line_item( $line_item_args );
    
    // Set due date
    $invoice->set("due_date_day=" . $day); // day
    $invoice->set("due_date_month=" . $month); // month
    $invoice->set("due_date_year=" . $year); // year
    
    // Set type
    $invoice->set("type=invoice");
    
    // Save invoice to database
    $invoice->save_invoice();

    Also there is some weird behavior when opening the individual invoices. I do not get the option to send notifications or view the invoice on frontend before I have pushed the “Save”-button.

    Here is two screenshots of a before/after pushing “Save”-button.
    Before save
    After save

    https://ww.wp.xz.cn/plugins/wp-invoice/

The topic ‘PHP function not saving invoice correctly’ is closed to new replies.