cf_si_add_invoice_meta

Function runs on cloning to create an invoice then adds the Invoice ID to the entries metablock This will allow the Invoice history to show up in the original entry modal.

Description

cf_si_add_invoice_meta( $new_post_id, $post_id, $new_post_type, $new_post_status ); 

Parameters (4)

0. $new_post_id
The new post id.
1. $post_id
The post id.
2. $new_post_type
The new post type.
3. $new_post_status
The new post status.

Usage

  1. if ( !function_exists( 'cf_si_add_invoice_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'caldera-forms-sprout-invoices-integration/cf-sprout-invoice.php'; 
  3.  
  4. // The new post id. 
  5. $new_post_id = null; 
  6.  
  7. // The post id. 
  8. $post_id = null; 
  9.  
  10. // The new post type. 
  11. $new_post_type = null; 
  12.  
  13. // The new post status. 
  14. $new_post_status = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = cf_si_add_invoice_meta($new_post_id, $post_id, $new_post_type, $new_post_status); 
  18.  

Defined (1)

The function is defined in the following location(s).

/cf-sprout-invoice.php  
  1. function cf_si_add_invoice_meta($new_post_id, $post_id, $new_post_type, $new_post_status) { 
  2. if($new_post_type === 'sa_invoice') { 
  3.  
  4. global $wpdb; 
  5. // I dont have a method to get entry by meta. I should add one. 
  6. $entry_meta_data = $wpdb->get_row($wpdb->prepare("SELECT `meta`.*, `entry`.* FROM `" . $wpdb->prefix ."cf_form_entry_meta` AS `meta` LEFT JOIN `" . $wpdb->prefix ."cf_form_entries` AS `entry` ON (`meta`.`entry_id` = `entry`.`id`) WHERE `meta_key` = 'estimate_id' AND `meta_value` = %d", $post_id), ARRAY_A); 
  7. if(!empty($entry_meta_data)) { 
  8. $new_meta = array( 
  9. 'entry_id' => $entry_meta_data['entry_id'],  
  10. 'process_id' => $entry_meta_data['process_id'],  
  11. 'meta_key' => 'invoice_id',  
  12. 'meta_value' => $new_post_id 
  13. ); 
  14. $wpdb->insert($wpdb->prefix ."cf_form_entry_meta", $new_meta); 
  15.  
  16.