function event_espresso_process_coupon($event_id, $event_cost, $mer) { do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, ''); $use_coupon_code = isset($_POST['use_coupon'][$event_id]) ? $_POST['use_coupon'][$event_id] : 'N'; if ($mer) { if (isset($_SESSION['espresso_session']['events_in_session'][$event_id]['coupon'])) { $coupon_code = isset($_SESSION['espresso_session']['events_in_session'][$event_id]['coupon']['code']) ? wp_strip_all_tags($_SESSION['espresso_session']['events_in_session'][$event_id]['coupon']['code']) : FALSE; $use_coupon_code = $coupon_code ? 'Y' : 'N'; } } else { $coupon_code = isset($_POST['event_espresso_coupon_code']) ? wp_strip_all_tags($_POST['event_espresso_coupon_code']) : ''; } return event_espresso_coupon_payment_page($event_id, $event_cost, $mer, $use_coupon_code); }
function espresso_filter_coupon_results($coupon_results, $event_id, $mer) { // echo '<h4>$event_id : ' . $event_id . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; // echo '<h4>$mer : ' . $mer . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; if (function_exists('event_espresso_coupon_payment_page') && isset($_POST['event_espresso_coupon_code'])) { $use_coupon_code = isset($_POST['use_coupon'][$event_id]) ? $_POST['use_coupon'][$event_id] : 'N'; //echo '<h4>$use_coupon_code : ' . $use_coupon_code . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; if ($results = event_espresso_coupon_payment_page($event_id, $coupon_results['event_cost'], $mer, $use_coupon_code)) { //printr( $results, '$results <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); $coupon_results['valid'] = $results['valid']; $coupon_results['error'] = $results['error']; $coupon_results['msg'] = $results['msg']; $coupon_results['event_cost'] = $results['valid'] ? number_format($results['event_cost'], 2, '.', '') : $coupon_results['event_cost']; add_filter('filter_hook_espresso_cart_modifier_strings', 'espresso_filter_cart_modifier_strings', 10, 2); add_filter('filter_hook_espresso_cart_coupon_events_array', 'espresso_filter_cart_coupon_events_array', 10, 2); } } return $coupon_results; }
function events_payment_page($attendee_id, $price_id = 0, $coupon_code = '', $groupon_code = '') { global $wpdb, $org_options, $simpleMath; $today = date("m-d-Y"); $num_people = 0; $Organization = $org_options['organization']; $Organization_street1 = $org_options['organization_street1']; $Organization_street2 = $org_options['organization_street2']; $Organization_city = $org_options['organization_city']; $Organization_state = $org_options['organization_state']; $Organization_zip = $org_options['organization_zip']; $contact = $org_options['contact_email']; $registrar = $org_options['contact_email']; $currency_format = getCountryFullData($org_options['organization_country']); $message = $org_options['message']; $return_url = $org_options['return_url']; $cancel_return = $org_options['cancel_return']; $notify_url = $org_options['notify_url']; $event_page_id = $org_options['event_page_id']; $attendees = $wpdb->get_results("SELECT * FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id ='" . $attendee_id . "'"); foreach ($attendees as $attendee) { //$attendee_id = $attendee->id; $attendee_last = $attendee->lname; $attendee_first = $attendee->fname; $attendee_address = $attendee->address; $attendee_address2 = $attendee->address2; $attendee_city = $attendee->city; $attendee_state = $attendee->state; $attendee_zip = $attendee->zip; $attendee_email = $attendee->email; //$attendee_organization_name = $attendee->organization_name; //$attendee_country = $attendee->country_id; $phone = $attendee->phone; $attendee_phone = $attendee->phone; $date = $attendee->date; $quantity = $attendee->quantity; $payment_status = $attendee->payment_status; $txn_type = $attendee->txn_type; //$event_cost = $attendee->amount_pd; $payment_date = $attendee->payment_date; $event_id = $attendee->event_id; $registration_id = $attendee->registration_id; } //$event_meta = event_espresso_get_event_meta($event_id); //Get the questions for the attendee $questions = $wpdb->get_results("SELECT ea.answer, eq.question\n\t\t\t\t\t\tFROM " . EVENTS_ANSWER_TABLE . " ea\n\t\t\t\t\t\tLEFT JOIN " . EVENTS_QUESTION_TABLE . " eq ON eq.id = ea.question_id\n\t\t\t\t\t\tWHERE ea.attendee_id = '" . $attendee_id . "' and eq.admin_only = 'N' ORDER BY eq.sequence asc "); //echo $wpdb->last_query; $display_questions = ''; foreach ($questions as $question) { $display_questions .= '<p>' . $question->question . ':<br /> ' . str_replace(',', '<br />', $question->answer) . '</p>'; } $num_peoplea = $wpdb->get_results("SELECT COUNT(registration_id) FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='" . $registration_id . "'", ARRAY_N); $num_people = $num_peoplea[0][0]; //If we are using the number of attendees dropdown, and if ($quantity > 1) { $num_people = $quantity; } $events = $wpdb->get_results("SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE id ='" . $event_id . "'"); foreach ($events as $event) { //$event_id = $event->id; $event_name = stripslashes_deep($event->event_name); $event_desc = stripslashes_deep($event->event_desc); $event_description = stripslashes_deep($event->event_desc); $event_identifier = $event->event_identifier; $send_mail = $event->send_mail; $active = $event->is_active; $conf_mail = $event->conf_mail; //$alt_email = $event->alt_email; //This is used to get the alternate email address that a payment can be made to using PayPal if (function_exists('event_espresso_coupon_payment_page')) { $use_coupon_code = $event->use_coupon_code; } if (function_exists('event_espresso_groupon_payment_page')) { $use_groupon_code = $event->use_groupon_code; } } $attendee_name = stripslashes_deep($attendee_first . ' ' . $attendee_last); //Figure out if the person has registered using a price selection if (!empty($_REQUEST['price_select']) && $_REQUEST['price_select'] == true) { $price_options = explode('|', $_REQUEST['price_option'], 2); $price_id = $price_options[0]; $price_type = $price_options[1]; $p_id = $price_id; $event_cost = event_espresso_get_final_price($price_id, $event_id); } elseif ($price_id > 0) { $event_cost = event_espresso_get_final_price($price_id, $event_id); $p_id = $price_id; } else { //$event_cost = $_POST['event_cost']; $event_cost = event_espresso_get_final_price($_POST['price_id'], $event_id); $p_id = $_POST['price_id']; } //Test the early discount amount to make sure we are getting the right amount //print_r(early_discount_amount($event_id, $event_cost)); $event_price = number_format($event_cost, 2, '.', ''); $event_price_x_attendees = number_format($event_cost * $num_people, 2, '.', ''); $event_original_cost = number_format($simpleMath->multiply($event_cost, $num_people), 2, '.', ''); /* * Added for seating chart addon */ /* * This code block overrides the cost using seating chart add-on price */ if (defined('ESPRESSO_SEATING_CHART')) { if (seating_chart::check_event_has_seating_chart($event_id) !== false) { $sc_cost_row = $wpdb->get_row("select sum(sces.purchase_price) as purchase_price from " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces inner join " . EVENTS_ATTENDEE_TABLE . " ea on sces.attendee_id = ea.id where ea.registration_id = '{$registration_id}'"); if ($sc_cost_row !== NULL) { $event_cost = number_format($sc_cost_row->purchase_price, 2, '.', ''); $event_original_cost = $event_cost; $event_price_x_attendees = $event_cost; } } } /* * End seating chart addon */ if (function_exists('event_espresso_coupon_payment_page') && (!empty($_REQUEST['coupon_code']) || !empty($coupon_code))) { $event_cost = event_espresso_coupon_payment_page($use_coupon_code, $event_id, $event_original_cost, $attendee_id, $num_people); /* * at this point , the $event_cost is correct * The next line divided by the number of people and reassigned it to the same $even_cost var, making the event cost less * I renamed it to another variable */ $event_price_x_attendees = number_format($event_cost, 2, '.', ''); $coupon_code = $_REQUEST['coupon_code']; } else { if (function_exists('event_espresso_groupon_payment_page') && ($_REQUEST['groupon_code'] != '' || $coupon_code != '')) { $event_cost = event_espresso_groupon_payment_page($use_groupon_code, $event_id, $event_original_cost, $attendee_id); $groupon_code = $_REQUEST['groupon_code']; } else { $event_cost = $event_original_cost; } } if ($num_people != 0) { $event_individual_cost = number_format($event_cost / $num_people, 2, '.', ''); } $event_discount_label = $event_original_cost > $event_cost ? ' (' . __('Discount of ', 'event_espresso') . $org_options['currency_symbol'] . number_format($event_original_cost - $event_cost, 2, ".", ",") . __(' applied', 'event_espresso') . ')' : ''; if ($event_cost == '0.00') { $event_cost = '0.00'; $payment_status = 'Completed'; $sql = array('amount_pd' => $event_cost, 'payment_status' => $payment_status, 'payment_date' => $today); $sql_data = array('%s', '%s', '%s'); } else { $sql = array('amount_pd' => $event_cost, 'payment_status' => $payment_status); $sql_data = array('%s', '%s'); } //Add the cost and payment status to the attendee $update_id = array('id' => $attendee_id); $wpdb->update(EVENTS_ATTENDEE_TABLE, $sql, $update_id, $sql_data, array('%d')); //If this is a group registration, we need to make sure all attendees have the same payment status if (espresso_count_attendees_for_registration($attendee_id) > 1) { $wpdb->query("UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}' WHERE registration_id ='" . $registration_id . "'"); } $display_cost = $event_cost != "0.00" ? $org_options['currency_symbol'] . $event_individual_cost : __('Free', 'event_espresso'); //Pull in the template if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "confirmation_display.php")) { require_once EVENT_ESPRESSO_TEMPLATE_DIR . "confirmation_display.php"; //This is the path to the template file if available } else { require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/confirmation_display.php"; } }
function event_espresso_calculate_total($update_section = null) { //print_r($_POST); global $wpdb; $events_in_session = $_SESSION['espresso_session']['events_in_session']; if (is_array($events_in_session)) { $event_total_cost = 0; foreach ($events_in_session as $k => $v) { $event_cost = 0; $event_id = $k; $event_individual_cost[$event_id] = 0; $start_time_id = ''; if (array_key_exists('start_time_id', $_POST) && array_key_exists($event_id, $_POST['start_time_id'])) { $start_time_id = $_POST['start_time_id'][$event_id]; } /* * two ways the price id comes this way * - from a dropdown >> price_id[event_id][price_id] * - from a radio >> price_id[event_id] with a value of price_id */ $price_id = $_POST['price_id'][$event_id]; if (is_array($price_id)) { foreach ($price_id as $_price_id => $val) { $attendee_quantitiy = $wpdb->escape($val); if ($attendee_quantitiy > 0) { $event_cost = event_espresso_get_final_price($_price_id, $event_id); $event_individual_cost[$event_id] += number_format($event_cost * $attendee_quantitiy, 2, '.', ''); } } } else { $attendee_quantitiy = 1; $event_cost = event_espresso_get_final_price($price_id, $event_id); $event_individual_cost[$event_id] = number_format($event_cost * $attendee_quantitiy, 2, '.', ''); } $_SESSION['espresso_session']['events_in_session'][$event_id]['cost'] = $event_individual_cost[$event_id]; $event_total_cost += $event_individual_cost[$event_id]; } $_SESSION['espresso_session']['pre_discount_total'] = number_format($event_total_cost, 2, '.', ''); if (function_exists('event_espresso_coupon_payment_page') && isset($_POST['event_espresso_coupon_code'])) { if (isset($_POST['event_espresso_coupon_code'])) { $event_total_cost = event_espresso_coupon_payment_page('Y', NULL, $event_total_cost, NULL); } } $grand_total = number_format($event_total_cost, 2, '.', ''); $_SESSION['espresso_session']['grand_total'] = $grand_total; event_espresso_update_item_in_session($update_section); } //} if ($update_section == null) { echo event_espresso_json_response(array('grand_total' => $grand_total)); die; } }