function event_espresso_get_final_price($price_id = FALSE, $event_id = FALSE, $orig_price = FALSE)
 {
     do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
     if (!$price_id || !$event_id) {
         return FALSE;
     }
     if (event_espresso_verify_price_id($price_id, $event_id) == FALSE) {
         $orig_price = espresso_return_single_price($event_id);
     }
     $result = $orig_price !== FALSE ? $orig_price : event_espresso_get_orig_price_and_surcharge($price_id, $event_id);
     if (isset($result->event_cost)) {
         $result->event_cost = (double) $result->event_cost;
     } else {
         $result = new stdClass();
         $result->event_cost = (double) $orig_price;
     }
     // if price is anything other than zero
     if ($result->event_cost > 0.0) {
         // Addition for Early Registration discount
         if ($early_price_data = early_discount_amount($event_id, $result->event_cost)) {
             $result->event_cost = $early_price_data['event_price'];
         }
     }
     if (event_espresso_verify_price_id($price_id, $event_id) == FALSE) {
         $result->event_cost = espresso_return_single_price($event_id);
     }
     $surcharge = event_espresso_calculate_surcharge($result->event_cost, $result->surcharge, $result->surcharge_type);
     $surcharge = !empty($surcharge) ? (double) $surcharge : 0;
     $event_cost = $result->event_cost + $surcharge;
     return (double) number_format($event_cost, 2, '.', '');
 }
 function event_espresso_get_final_price($price_id = FALSE, $event_id = FALSE)
 {
     do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
     if (!$price_id || !$event_id) {
         return 1000000;
     }
     global $wpdb;
     $sql = "SELECT id, event_cost, surcharge, surcharge_type FROM " . EVENTS_PRICES_TABLE . " WHERE id='" . $price_id . "' ORDER BY id ASC LIMIT 1";
     if (is_user_logged_in()) {
         $sql = "SELECT id, member_price event_cost, surcharge, surcharge_type FROM " . EVENTS_PRICES_TABLE . " WHERE id='" . $price_id . "' ORDER BY id ASC LIMIT 1";
     }
     do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, 'sql=' . $sql);
     $results = $wpdb->get_results($sql);
     foreach ($results as $result) {
         if ($wpdb->num_rows >= 1) {
             if ($result->event_cost > 0.0) {
                 $event_cost = $result->event_cost;
                 // Addition for Early Registration discount
                 if ($early_price_data = early_discount_amount($event_id, $event_cost)) {
                     $event_cost = $early_price_data['event_price'];
                 }
                 $surcharge = $result->surcharge;
                 //by default it's 0. if flat rate, will just be formatted and atted to the total
                 if ($result->surcharge > 0 && $result->surcharge_type == 'pct') {
                     //if >0 and is percent, calculate surcharg amount to be added to total
                     $surcharge = $event_cost * $result->surcharge / 100;
                 }
                 $event_cost += $surcharge;
             } else {
                 $event_cost = __('0.00', 'event_espresso');
             }
         } else {
             if ($wpdb->num_rows == 0) {
                 $event_cost = __('0.00', 'event_espresso');
             }
         }
     }
     if (event_espresso_verify_price_id($price_id, $event_id) == FALSE) {
         $event_cost = espresso_return_single_price($event_id);
     }
     return empty($event_cost) ? 0 : $event_cost;
 }