Skip to content

Instantly share code, notes, and snippets.

@sidharrell
Last active December 19, 2015 08:19
Show Gist options
  • Save sidharrell/5924952 to your computer and use it in GitHub Desktop.
Save sidharrell/5924952 to your computer and use it in GitHub Desktop.
new email shortcodes for original price and surcharge
function get_price_breakdown($attendee_id) {
global $wpdb;
$sql = "SELECT * FROM " . EVENTS_PRICES_TABLE . " p JOIN ";
$sql .= EVENTS_ATTENDEE_TABLE . " a ON (a.event_id = p.event_id AND a.price_option = (p.price_type OR p.member_price_type)) ";
$sql .= "WHERE a.id = %d;";
$temp = $wpdb->get_row($wpdb->prepare($sql, $attendee_id), ARRAY_A);
if ($temp['price_option'] == $temp['price_type']) {
$temp['pre_surcharge_price'] = $temp['event_cost'];
} else {
$temp['pre_surcharge_price'] = $temp['member_price'];
}
return $temp;
}
function replace_shortcodes($message, $data) {
global $wpdb, $org_options;
$payment_data = espresso_get_total_cost(array('attendee_session'=>$data->attendee->attendee_session));
$event_cost = $payment_data['total_cost'];
$price_breakdown = get_price_breakdown($data->attendee->id);
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
$SearchValues = array(
"[event_id]",
"[event_identifier]",
"[registration_id]",
"[fname]",
"[lname]",
"[phone]",
"[event]",
"[event_name]",
"[description]",
"[event_link]",
"[event_url]",
"[virtual_url]",
"[virtual_phone]",
"[venue_title]",
"[venue_url]",
"[venue_image]",
"[venue_phone]",
"[venue_address]", //shows the venue address
"[txn_id]",
"[cost]",
"[event_price]",
"[ticket_qty]",
"[ticket_type]",
"[ticket_link]",
"[certificate_link]",
"[contact]",
"[company]",
"[co_add1]",
"[co_add2]",
"[co_city]",
"[co_state]",
"[co_zip]",
"[payment_url]",
"[invoice_link]",
"[start_date]",
"[start_time]",
"[end_date]",
"[end_time]",
"[location]",
"[location_phone]",
"[google_map_link]",
"[attendee_event_list]", //Creates a table of the attendee and event information
"[custom_questions]",
"[qr_code]",
"[seating_tag]",
"[edit_attendee_link]",
"[add_to_calendar]",
"[pre_surcharge_price]",
"[surcharge]"
);
$ReplaceValues = array(
$data->attendee->event_id,
$data->event->event_identifier,
$data->attendee->registration_id,
$data->attendee->fname,
$data->attendee->lname,
$data->event->venue_phone,
$data->event->event_name,
$data->event->event_name,
$data->event->event_desc,
$data->event_link,
$data->event_url,
$data->event->virtual_url,
$data->event->virtual_phone,
//Venue information
$data->event->venue_name,
$data->event->venue_url,
$data->event->venue_image,
$data->event->venue_phone,
$data->location, //For the "[venue_address]" shortcode shows the venue address
//Payment details
$data->attendee->txn_id,
$org_options['currency_symbol'] . $event_cost,
$org_options['currency_symbol'] . $event_cost,
$data->attendee->quantity,
$data->attendee->price_option,
$data->ticket_link,
empty($data->certificate_link) ? '' : $data->certificate_link,
empty($data->event->alt_email) ? $org_options['contact_email'] : $data->event->alt_email,
//Organization details
$org_options['organization'],
$org_options['organization_street1'],
$org_options['organization_street2'],
$org_options['organization_city'],
$org_options['organization_state'],
$org_options['organization_zip'],
$data->payment_link,
$data->invoice_link,
event_date_display($data->attendee->start_date),
event_date_display($data->attendee->event_time, get_option('time_format')),
event_date_display($data->attendee->end_date),
event_date_display($data->attendee->end_time, get_option('time_format')),
$data->location,
$data->event->venue_phone,
$data->google_map_link,
$data->table_open . $data->table_heading . $data->event_table . $data->table_close,
isset($data->email_questions) && !empty($data->email_questions) ? $data->email_questions : '',
$data->qr_code,
$data->seatingchart_tag,
$data->edit_attendee,
//Add to calendar link
apply_filters('filter_hook_espresso_display_ical', array(
'event_id' => $data->attendee->event_id,
'registration_id' => $data->attendee->registration_id,
'event_name' => $data->event->event_name,
'event_desc' => wp_kses($data->event->event_desc,array()),
'contact_email' => empty($data->event->alt_email) ? $org_options['contact_email'] : $data->event->alt_email,
'start_time' => empty($event->start_time) ? '' : $event->start_time,
'start_date' => event_date_display($data->attendee->start_date, get_option('date_format')),
'end_date' => event_date_display($data->attendee->end_date, get_option('date_format')),
'start_time' => empty($data->attendee->event_time) ? '' : $data->attendee->event_time,
'end_time' => empty($data->attendee->end_time) ? '' : $data->attendee->end_time,
'location' => $data->location,
), '', '', TRUE
),
$price_breakdown['pre_surcharge_price'],
$price_breakdown['surcharge']
);
//Get the questions and answers
$questions = $wpdb->get_results("select qst.question as question, ans.answer as answer from " . EVENTS_ANSWER_TABLE . " ans inner join " . EVENTS_QUESTION_TABLE . " qst on ans.question_id = qst.id where ans.attendee_id = " . $data->attendee->id, ARRAY_A);
//echo '<p>'.print_r($questions).'</p>';
if ($wpdb->num_rows > 0 && $wpdb->last_result[0]->question != NULL) {
foreach ($questions as $q) {
$k = stripslashes( $q['question'] );
$v = stripslashes( $q['answer'] );
//Output the question
array_push($SearchValues, "[" . 'question_' . $k . "]");
array_push($ReplaceValues, $k);
//Output the answer
array_push($SearchValues, "[" . 'answer_' . $k . "]");
array_push($ReplaceValues, rtrim($v, ",") );
}
}
//Get the event meta
//echo '<p>'.print_r($data->event->event_meta).'</p>';
if (!empty($data->event->event_meta)) {
foreach ($data->event->event_meta as $k => $v) {
if (!empty($k) && !is_array($v)) {
array_push($SearchValues, "[" . $k . "]");
array_push($ReplaceValues, stripslashes_deep($v));
}
}
}
//Perform the replacement
return str_replace($SearchValues, $ReplaceValues, $message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment