Title: Notifications programmatically?
Last modified: July 23, 2022

---

# Notifications programmatically?

 *  Resolved [aggk](https://wordpress.org/support/users/aggk/)
 * (@aggk)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/notifications-programmatically/)
 * Hi,
 * I tried generating an invoice programmatically with the help of these snippets:
 * First creating the client
    [https://docs.sproutinvoices.com/article/73-creating-a-sprout-invoices-client-and-Then](https://docs.sproutinvoices.com/article/73-creating-a-sprout-invoices-client-and-Then)
   the invoice [https://docs.sproutinvoices.com/article/80-creating-an-invoice-with-sprout-invoices](https://docs.sproutinvoices.com/article/80-creating-an-invoice-with-sprout-invoices)
 * This seems to work great however the invoice is not sent out and no notifications.
   
   I can do this manually from the invoice but wonder if this can be done programmatically
   also just after the invoice is created?
 * …I was also wondering if the invoices has to be public or if there can be some
   sort of private string/key there?
 * Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Contributor [Elana Davis](https://wordpress.org/support/users/elanasparkle/)
 * (@elanasparkle)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/notifications-programmatically/#post-15860263)
 * Hello [@aggk](https://wordpress.org/support/users/aggk/),
 * ​Thank you for reaching out to support! You can do it a few different ways but
   the easiest way would be to add the action of sa_new_invoice after your invoice
   is created. You would want to make sure you set the status to pending beforehand.
   I do that with SI_Invoice STATUS_PENDING like in the below Gist. Also, below 
   is the full function to send a notification on invoice creation.
 * [https://gist.github.com/elanasparkle/104bec2ae0b6f93e47200b219e2a7d55](https://gist.github.com/elanasparkle/104bec2ae0b6f93e47200b219e2a7d55)
 *     ```
       function send_invoice_on_creation( SI_Invoice $invoice ) {
       	$client = $invoice->get_client();
       	if ( ! is_a( $client, 'SI_Client' ) ) {
       		return;
       	}
       	$recipients = $client->get_associated_users();
       	if ( empty( $recipients ) ) {
       		return;
       	}
       	do_action( 'send_invoice', $invoice, $recipients );
       }
       add_action( 'sa_new_invoice',  'send_invoice_on_creation' );
       ```
   
 * Let me know if that works for you or if you need anything further.
 * Thanks
    Elana D.
 *  Plugin Contributor [Elana Davis](https://wordpress.org/support/users/elanasparkle/)
 * (@elanasparkle)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/notifications-programmatically/#post-15885206)
 * Hello [@aggk](https://wordpress.org/support/users/aggk/),
 * I haven’t heard from you and per our support policies, I’m going to mark this
   as resolved. Don’t hesitate to reach out if you are still having any issues or
   need anything further.
 * Thanks
    Elana D.
 *  [Ski_K2](https://wordpress.org/support/users/ski_k2/)
 * (@ski_k2)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/notifications-programmatically/#post-16323194)
 * Is this snippet required for the paid/Freelancer version or is the invoice emailed
   automatically on creation? With both manually and recurring?
 *  Plugin Contributor [Elana Davis](https://wordpress.org/support/users/elanasparkle/)
 * (@elanasparkle)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/notifications-programmatically/#post-16325797)
 * Hello [@ski_k2](https://wordpress.org/support/users/ski_k2/),
   For the recurring
   invoices the notification will go out automatically, along with the invoices 
   scheduled for future dates. If you are manually creating an invoice for today
   you would need to send the notification in the notification section of the edit
   invoice screen. However, this hook will remove that manual process for newly 
   created invoices and always send the notification on manual invoices that are
   not scheduled for the future. ThanksElana D.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Notifications programmatically?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/sprout-invoices_d1d1d1.svg)
 * [Client Invoicing by Sprout Invoices - Easy Estimates and Invoices for WordPress](https://wordpress.org/plugins/sprout-invoices/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sprout-invoices/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sprout-invoices/)
 * [Active Topics](https://wordpress.org/support/plugin/sprout-invoices/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sprout-invoices/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sprout-invoices/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [Elana Davis](https://wordpress.org/support/users/elanasparkle/)
 * Last activity: [3 years, 3 months ago](https://wordpress.org/support/topic/notifications-programmatically/#post-16325797)
 * Status: resolved