Title: PHP function not saving invoice correctly
Last modified: August 30, 2016

---

# PHP function not saving invoice correctly

 *  [cjohannesen](https://wordpress.org/support/users/cjohannesen/)
 * (@cjohannesen)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/php-function-not-saving-invoice-correctly/)
 * 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](http://johannesen.co/wpi-problem/before-save.png)
   [After save](http://johannesen.co/wpi-problem/after-save.png)
 * [https://wordpress.org/plugins/wp-invoice/](https://wordpress.org/plugins/wp-invoice/)

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

 * ![](https://s.w.org/plugins/geopattern-icon/wp-invoice_c36510.svg)
 * [WP-Invoice - Web Invoice and Billing](https://wordpress.org/plugins/wp-invoice/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-invoice/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-invoice/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-invoice/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-invoice/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-invoice/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [cjohannesen](https://wordpress.org/support/users/cjohannesen/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/php-function-not-saving-invoice-correctly/)
 * Status: not resolved