Skip to content

Instantly share code, notes, and snippets.

@vfontjr
Last active January 16, 2019 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfontjr/ae47098b6d3a2b4bc57e6404d74aaa88 to your computer and use it in GitHub Desktop.
Save vfontjr/ae47098b6d3a2b4bc57e6404d74aaa88 to your computer and use it in GitHub Desktop.
<?php
/*
Function Name: Create Thank You form Entries
Description: Creates one entry in Thank You form for each winner recorded in repeatable field section of invoice form.
Version: 1.0
Author: Victor M. Font Jr.
Author URI: https://victorfont.com/
*/
/* add the action at a higher priority than 41 so it executes after Zaperi add-on */
add_action("frm_after_update_entry","create_thank_you_form_winner_entries", 50, 2);
function create_thank_you_form_winner_entries( $entry_id, $form_id ) {
/* create the entries if the invoice form is updated and invoice has been paid */
if ($form_id == "8" && $_POST['item_meta'][158] == "true") {
global $wpdb;
/* populate the common field variables for all new entries */
/* Report Information */
$report_completed_by2 = $_POST['item_meta'][137]; // #ISSUE: check condition for 'other'
/* Organization Information */
$org_legal_name2 = $_POST['item_meta'][138];
$org_billing_address2 = $_POST['item_meta'][139];
/* Event Information */
$event_name2 = $_POST['item_meta'][140];
$event_date2 = $_POST['item_meta'][141];
$book_by_date2 = $_POST['item_meta'][142];
$travel_by_date2 = $_POST['item_meta'][143];
/* Event Contact Information */
$event_contact_last_name2 = $_POST['item_meta'][96];
$event_contact_first_name2 = $_POST['item_meta'][97];
$event_contact_phone2 = $_POST['item_meta'][99];
$event_contact_email2 = $_POST['item_meta'][98];
/* Sales Information */
$use_auctioneer2 = $_POST['item_meta'][104];
$auctioneer_name2 = $_POST['item_meta'][105];
$auctioneer_company2 = $_POST['item_meta'][106];
$auctioneer_email2 = $_POST['item_meta'][107];
$use_sav_sales2 = $_POST['item_meta'][110];
$sav_sales_name2 = $_POST['item_meta'][111];
/* Invoice Information */
$num_winners2 = $_POST['item_meta'][118];
$invoice_total2 = $_POST['item_meta'][119];
$email_invoice_to2 = $_POST['item_meta'][120];
$send_additional_email2 = $_POST['item_meta'][121];
$additional_email2 = $_POST['item_meta'][122];
/* Internal Information */
$invoice_num2 = $_POST['item_meta'][126];
$disable_qb2 = $_POST['item_meta'][127];
$admin_emails_only2 = $_POST['item_meta'][128];
$invoice_unique_id2 = $_POST['item_meta'][130];
$date_time_submitted2 = $_POST['item_meta'][129];
$invoice_paid2 = $_POST['item_meta'][158];
$form_id2 = '41'; /* PUID/Congrats form */
$user = $_POST['frm_user_id'];
/* start the loop */
foreach($_POST['item_meta'][115]['row_ids'] as $row_id) {
/* Winner Information */
$winner_last_name2 = $_POST['item_meta'][115][$row_id][72];
$winner_package_code2 = $_POST['item_meta'][115][$row_id][73];
$winner_destination2 = $_POST['item_meta'][115][$row_id][74];
$winner_unit_type2 = $_POST['item_meta'][115][$row_id][75];
$winner_num_nights2 = $_POST['item_meta'][115][$row_id][76];
$winner_cost_to_org2 = $_POST['item_meta'][115][$row_id][77];
$winners_increment2 = $_POST['item_meta'][115][$row_id][78];
$sanitized_package_code2 = $_POST['item_meta'][115][$row_id][79];
$date_time2 = $_POST['item_meta'][115][$row_id][80];
$winner_unique_id2 = $_POST['item_meta'][115][$row_id][81];
$attached_invoice_unique_id = $_POST['item_meta'][115][$row_id][392];
$package_registered2 = $_POST['item_meta'][115][$row_id][390];
// #ISSUE: check if we need to do updates
$update_record = false;
if($update_record) {
// update record if it already exists
// this capability not required by client. This stub code is for future use if it becomes a requirement
} else {
//create entry for each winner
FrmEntry::create(array(
'form_id' => $form_id2,
'item_key' => FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ),
'frm_user_id' => $user,
'item_meta' => array(
554 => $report_completed_by2,
557 => $org_legal_name2,
558 => $org_billing_address2,
561 => $event_name2,
562 => $event_date2,
563 => $book_by_date2,
563 => $travel_by_date2,
568 => $event_contact_last_name2,
569 => $event_contact_first_name2,
570 => $event_contact_phone2,
571 => $event_contact_email2,
574 => $use_auctioneer2,
575 => $auctioneer_name2,
576 => $auctioneer_company2,
577 => $auctioneer_email2,
578 => $use_sav_sales2,
579 => $sav_sales_name2,
583 => $winner_last_name2,
584 => $winner_package_code2,
585 => $winner_destination2,
586 => $winner_unit_type2,
587 => $winner_num_nights2,
588 => $winner_cost_to_org2,
589 => $winners_increment2,
590 => $sanitized_package_code2,
591 => $date_time2,
592 => $winner_unique_id2,
593 => $attached_invoice_unique_id,
594 => $package_registered2,
598 => $num_winners2,
599 => $invoice_total2,
600 => $email_invoice_to2,
601 => $send_additional_email2,
602 => $additional_email2,
606 => $invoice_num2,
607 => $disable_qb2,
608 => $admin_emails_only2,
609 => $invoice_unique_id2,
610 => $date_time_submitted2,
611 => $invoice_paid2,
),
));
}
} // end loop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment