Skip to content

Instantly share code, notes, and snippets.

@minisemi
Last active August 27, 2018 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save minisemi/2ce0a54efe806b74db19bda184a662f4 to your computer and use it in GitHub Desktop.
Save minisemi/2ce0a54efe806b74db19bda184a662f4 to your computer and use it in GitHub Desktop.
Sprout settings
add_filter( 'si_discount_after_taxes', '__return_false', 1);
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
// Setting this doesn't affect the total at all
'total' => '', // invoice total
'po_number' => '', // PO number
'discount' => 20, // discount
'tax' => (float) 25, // 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',
'rate' => 350,
'qty' => 1,
'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