-
-
Save dancameron/c07eefd72baee9b223ae5d60bce9b75c to your computer and use it in GitHub Desktop.
Sprout settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // don't include this line in your functions.php, since it already starts with it. | |
function process_ninja_form_and_create_invoice( $entry = array() ) { | |
$fields = $entry['fields_by_key']; | |
$address = array( | |
'street' => $fields['address_1530704017856']['value'], | |
'city' => $fields['city_1530704053248']['value'], | |
'zone' => '', | |
'postal_code' => $fields['postal_code_1530704039567']['value'], | |
'country' => 'Sweden', | |
); | |
$args = array( | |
'company_name' => $fields['nf_field_foretag']['value'], // required | |
'website' => '', // optional | |
'address' => $address, // optional | |
'user_id' => '' // optional | |
); | |
$client_id = SI_Client::new_client( $args ); | |
$data = array( | |
'subject' => $fields['reference_numb_1532682390724']['value'] . ' - ' . $fields['nf_field_foretag']['value'] . ' (' . $fields['nf_field_org_numb']['value'] . ')', // title | |
'user_id' => '', // user id that created the invoice | |
'invoice_id' => $fields['reference_numb_1532682390724']['value'], // Invoice #/ID | |
'estimate_id' => '', // Associated Estimate ID (post_id) | |
'client_id' => $client_id, // Associated Client ID (post_id) | |
'project_id' => '', // Associated Project ID (post_id) | |
'status' => 'pending', // temp, publish, future, partial, complete, write-off | |
'deposit' => (float) 0, // deposit amount | |
// this is the total minus any discounts | |
'total' => 280, // invoice total | |
'po_number' => '', // PO number | |
// this provides a 20% discount | |
'discount' => 20, // discount | |
'tax' => (float) 0, // Tax | |
'tax2' => (float) 0, // Tax 2 | |
'notes' => '', // Notes | |
'terms' => '', // Terms | |
'issue_date' => time(), // Issue Date (timestamp) | |
'due_date' => $fields['invoice_due_date_1534002818312']['value'], // Due Date (timestamp) | |
'expiration_date' => 0, // Expiration date (timestamp) | |
'line_items' => array( // example of two line items | |
array( | |
'type' => 'service', | |
// Set the rate and qty | |
'rate' => 280, | |
'qty' => 1, | |
// this is a percentage | |
'tax' => 25, | |
// total includes tax | |
'total' => 350, | |
'desc' => $fields['language_1530703794562']['value'], | |
) | |
), // associated array of line items | |
); | |
$invoice_id = SI_Invoice::create_invoice( $data ); | |
} | |
add_action( 'ninja_forms_after_submission', 'process_ninja_form_and_create_invoice', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet is a customization for Sprout Invoices. A customizable solution that provides a way for you to get paid via your WordPress site. For more information please don't hesitate to reach out.