-
-
Save Pebblo/6d28d2e4450c8fd6c299 to your computer and use it in GitHub Desktop.
A custom_functions.php containing a function you can edit to make changes to the MER Payment Overview Table.
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 | |
//This is a custom_functions.php file containing the function event_espresso_add_attendees_to_db_multi() | |
//to be used to allow customisations to the MER Payment Overview table. | |
//Place this file within wp-content/uploads/espresso/ | |
//or if you are already using the custom files add-on add the below function to your custom_functions.php file | |
//The MER Payment Overview table is output from lines 147 - 202 | |
function event_espresso_add_attendees_to_db_multi() { | |
//echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; | |
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, ''); | |
global $wpdb, $org_options; | |
if ( espresso_verify_recaptcha() ) { | |
$primary_registration_id = NULL; | |
$multi_reg = true; | |
$events_in_session = $_SESSION['espresso_session']['events_in_session']; | |
if (event_espresso_invoke_cart_error($events_in_session)) { | |
return false; | |
} | |
$count_of_events = count($events_in_session); | |
$current_session_id = $_SESSION['espresso_session']['id']; | |
$biz_name = $count_of_events . ' ' . $org_options['organization'] . __(' events', 'event_espresso'); | |
$event_cost = $_SESSION['espresso_session']['grand_total']; | |
$event_cost = apply_filters('filter_hook_espresso_cart_grand_total', $event_cost); | |
// If there are events in the session, add them one by one to the attendee table | |
if ($count_of_events > 0) { | |
foreach ($events_in_session as $event_id => $event) { | |
$event_meta = event_espresso_get_event_meta($event_id); | |
$session_vars['data'] = $event; | |
if ( is_array( $event['event_attendees'] )) { | |
$counter = 1; | |
//foreach price type in event attendees | |
foreach ( $event['event_attendees'] as $price_id => $event_attendees ) { | |
$session_vars['data'] = $event; | |
foreach ( $event_attendees as $attendee) { | |
$attendee['price_id'] = $price_id; | |
//this has all the attendee information, name, questions.... | |
$session_vars['event_attendees'] = $attendee; | |
$session_vars['data']['price_type'] = stripslashes_deep($event['price_id'][$price_id]['price_type']); | |
if ( isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == 1 ) { | |
$num_people = (int)$event['price_id'][$price_id]['attendee_quantity']; | |
$session_vars['data']['num_people'] = empty($num_people) || $num_people == 0 ? 1 : $num_people; | |
} | |
// ADD ATTENDEE TO DB | |
$return_data = event_espresso_add_attendees_to_db( $event_id, $session_vars, TRUE ); | |
if (!empty($return_data['registration_id'])) $session_vars['data']['attendee_quantity']--; | |
$tmp_registration_id = $return_data['registration_id']; | |
$notifications = $return_data['notifications']; | |
if ($primary_registration_id === NULL) { | |
$primary_registration_id = $tmp_registration_id; | |
} | |
$SQL = "SELECT * FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " "; | |
$SQL .= "WHERE primary_registration_id = %s AND registration_id = %s"; | |
$check = $wpdb->get_row( $wpdb->prepare( $SQL, $primary_registration_id, $tmp_registration_id )); | |
if ( $check === NULL) { | |
$tmp_data = array( 'primary_registration_id' => $primary_registration_id, 'registration_id' => $tmp_registration_id ); | |
$wpdb->insert( EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE, $tmp_data, array( '%s', '%s' )); | |
} | |
$counter++; | |
} | |
} | |
} | |
} | |
$SQL = "SELECT a.*, ed.id AS event_id, ed.event_name, dc.coupon_code_price, dc.use_percentage "; | |
$SQL .= "FROM " . EVENTS_ATTENDEE_TABLE . " a JOIN " . EVENTS_DETAIL_TABLE . " ed ON a.event_id=ed.id "; | |
$SQL .= "LEFT JOIN " . EVENTS_DISCOUNT_CODES_TABLE . " dc ON a.coupon_code=dc.coupon_code "; | |
$SQL .= "WHERE attendee_session=%s ORDER BY a.id ASC"; | |
$attendees = $wpdb->get_results( $wpdb->prepare( $SQL, $current_session_id )); | |
$quantity = 0; | |
$sub_total = 0; | |
$discounted_total = 0; | |
$discount_amount = 0; | |
$is_coupon_pct = ! empty( $attendees[0]->use_percentage ) && $attendees[0]->use_percentage == 'Y' ? TRUE : FALSE; | |
//printr( $attendees, '$attendees <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); | |
foreach ($attendees as $attendee) { | |
if ( $attendee->is_primary ) { | |
$primary_attendee_id = $attendee_id = $attendee->id; | |
$coupon_code = $attendee->coupon_code; | |
$event_id = $attendee->event_id; | |
$fname = $attendee->fname; | |
$lname = $attendee->lname; | |
$address = $attendee->address; | |
$city = $attendee->city; | |
$state = $attendee->state; | |
$country = $attendee->country_id; | |
$zip = $attendee->zip; | |
$attendee_email = $attendee->email; | |
$registration_id = $attendee->registration_id; | |
} | |
$quantity += (int)$attendee->quantity; | |
$sub_total += (int)$attendee->quantity * $attendee->orig_price; | |
$discounted_total += (int)$attendee->quantity * $attendee->final_price; | |
} | |
$discount_amount = $sub_total - $discounted_total; | |
$total_cost = $discounted_total; | |
$total_cost = $total_cost < 0 ? 0.00 : (float)$total_cost; | |
if ( function_exists( 'espresso_update_attendee_coupon_info' ) && $primary_attendee_id && ! empty( $attendee->coupon_code )) { | |
espresso_update_attendee_coupon_info( $primary_attendee_id, $attendee->coupon_code ); | |
} | |
if ( function_exists( 'espresso_update_groupon' ) && $primary_attendee_id && ! empty( $coupon_code )) { | |
espresso_update_groupon( $primary_attendee_id, $coupon_code ); | |
} | |
espresso_update_primary_attendee_total_cost( $primary_attendee_id, $total_cost, __FILE__ ); | |
if ( ! empty( $notifications['coupons'] ) || ! empty( $notifications['groupons'] )) { | |
echo '<div id="event_espresso_notifications" class="clearfix event-data-display no-hide">'; | |
echo $notifications['coupons']; | |
// add space between $coupon_notifications and $groupon_notifications ( if any $groupon_notifications exist ) | |
echo ! empty( $notifications['coupons'] ) && ! empty( $notifications['groupons'] ) ? '<br/>' : ''; | |
echo $notifications['groupons']; | |
echo '</div>'; | |
} | |
//Post the gateway page with the payment options | |
if ( $total_cost > 0 ) { | |
?> | |
<div class="espresso_payment_overview event-display-boxes ui-widget" > | |
<h3 class="section-heading ui-widget-header ui-corner-top"> | |
<?php _e('Payment Overview', 'event_espresso'); ?> | |
</h3> | |
<div class="event-data-display ui-widget-content ui-corner-bottom" > | |
<div class="event-messages ui-state-highlight"> <span class="ui-icon ui-icon-alert"></span> | |
<p class="instruct"> | |
<?php _e('Your registration is not complete until payment is received.', 'event_espresso'); ?> | |
</p> | |
</div> | |
<p><?php echo $org_options['email_before_payment'] == 'Y' ? __('A confirmation email has been sent with additional details of your registration.', 'event_espresso') : ''; ?></p> | |
<table> | |
<?php foreach ($attendees as $attendee) { ?> | |
<tr> | |
<td width="70%"> | |
<?php echo '<strong>'.stripslashes_deep($attendee->event_name ) . '</strong>'?> - <?php echo stripslashes_deep( $attendee->price_option ) ?> <?php echo $attendee->final_price < $attendee->orig_price ? '<br /> <span style="font-size:.8em;">' . $org_options['currency_symbol'] . number_format($attendee->orig_price - $attendee->final_price, 2) . __(' discount per registration','event_espresso') . '</span>' : ''; ?><br/> | |
<?php echo __('Attendee:','event_espresso') . ' ' . stripslashes_deep($attendee->fname . ' ' . $attendee->lname) ?> | |
</td> | |
<td width="10%"><?php echo $org_options['currency_symbol'] . number_format($attendee->final_price, 2); ?></td> | |
<td width="10%"><?php echo 'x ' . (int)$attendee->quantity ?></td> | |
<td width="10%" style="text-align:right;"><?php echo $org_options['currency_symbol'] . number_format( $attendee->final_price * (int)$attendee->quantity, 2) ?></td> | |
</tr> | |
<?php } ?> | |
<tr> | |
<td colspan="3"><?php _e('Sub-Total:','event_espresso'); ?></td> | |
<td colspan="" style="text-align:right"><?php echo $org_options['currency_symbol'] . number_format($sub_total, 2); ?></td> | |
</tr> | |
<?php | |
if (!empty($discount_amount)) { | |
?> | |
<tr> | |
<td colspan="3"><?php _e('Total Discounts:','event_espresso'); ?></td> | |
<td colspan="" style="text-align:right"><?php echo '-' . $org_options['currency_symbol'] . number_format( $discount_amount, 2 ); ?></td> | |
</tr> | |
<?php } ?> | |
<tr> | |
<td colspan="3"><strong class="event_espresso_name"> | |
<?php _e('Total Amount due: ', 'event_espresso'); ?> | |
</strong></td> | |
<td colspan="" style="text-align:right"><?php echo $org_options['currency_symbol'] ?><?php echo number_format($total_cost,2); ?></td> | |
</tr> | |
</table> | |
<p class="event_espresso_refresh_total"> | |
<a href="?page_id=<?php echo $org_options['event_page_id']; ?>®event_action=show_shopping_cart"> | |
<?php _e('Edit Cart', 'event_espresso'); ?> | |
</a> | |
<?php _e(' or ', 'event_espresso'); ?> | |
<a href="?page_id=<?php echo $org_options['event_page_id']; ?>®event_action=load_checkout_page"> | |
<?php _e('Edit Registrant Information', 'event_espresso'); ?> | |
</a> | |
</p> | |
</div> | |
</div> | |
<br/><br/> | |
<?php | |
//Show payment options | |
if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php")) { | |
require_once(EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php"); | |
} else { | |
require_once(EVENT_ESPRESSO_PLUGINFULLPATH . "gateways/gateway_display.php"); | |
} | |
//Check to see if the site owner wants to send an confirmation eamil before payment is recieved. | |
if ($org_options['email_before_payment'] == 'Y') { | |
event_espresso_email_confirmations(array('session_id' => $_SESSION['espresso_session']['id'], 'send_admin_email' => 'true', 'send_attendee_email' => 'true', 'multi_reg' => true)); | |
} | |
} elseif ( $total_cost == 0.00 ) { | |
?> | |
<p> | |
<?php _e('Thank you! Your registration is confirmed for', 'event_espresso'); ?> | |
<strong><?php echo stripslashes_deep( $biz_name ) ?></strong></p> | |
<p> | |
<?php _e('A confirmation email has been sent with additional details of your registration.', 'event_espresso'); ?> | |
</p> | |
<?php | |
event_espresso_email_confirmations(array('session_id' => $_SESSION['espresso_session']['id'], 'send_admin_email' => 'true', 'send_attendee_email' => 'true', 'multi_reg' => true)); | |
event_espresso_clear_session(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment