/event_espresso_price_list.php Secret
Last active
December 18, 2015 12:19
-
-
Save Apina/674700c14fe7d751be75 to your computer and use it in GitHub Desktop.
No longer valid - EE3 now supports this in the Template options.
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 function should be added to the custom files addon, in the wp-content/uploads/espresso/custom_functions.php file, or your in your theme, in the wp-content/themes/theme-name/functions.php. | |
if (!function_exists('event_espresso_price_list')) { | |
function event_espresso_price_list($event_id) { | |
$html = ''; | |
global $wpdb, $org_options; | |
$sql = "SELECT id, event_cost, surcharge, surcharge_type, price_type"; | |
$order_by = 'event_cost'; | |
if ( function_exists('espresso_members_installed') && espresso_members_installed() == true && is_user_logged_in() ) { | |
$sql .= ", member_price, member_price_type "; | |
$member_event = TRUE; | |
$order_by = 'member_price'; | |
} | |
$sql .= " FROM " . EVENTS_PRICES_TABLE . " WHERE event_id='" . $event_id . "' ORDER BY " . $order_by . " ASC"; | |
$results = $wpdb->get_results( $wpdb->prepare($sql, '') ); | |
if ($wpdb->num_rows > 1) { | |
//Create a dropdown of prices | |
$html .= '<ul id="price-list-' . $event_id . '" class="espresso-price-list">'; | |
foreach ($results as $result) { | |
if ($member_event == TRUE) { | |
$result->event_cost = $result->member_price; | |
$result->price_type = $result->member_price_type; | |
} | |
// 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']; | |
$message = __(' Early Pricing', 'event_espresso'); | |
} else { | |
$message = ''; | |
} | |
$surcharge = ''; | |
if ($result->surcharge > 0 && $result->event_cost > 0.00) { | |
$surcharge = " + {$org_options['currency_symbol']}{$result->surcharge} " . $surcharge_text; | |
if ($result->surcharge_type == 'pct') { | |
$surcharge = " + {$result->surcharge}% " . $surcharge_text; | |
} | |
} | |
$html .= '<li>' . stripslashes_deep($result->price_type) . ' (' . $org_options['currency_symbol'] . number_format($result->event_cost, 2) . $message . ') ' . $surcharge . ' </li>'; | |
} | |
$html .= '</ul>'; | |
}else{ | |
if ($member_event == TRUE) { | |
$event_cost = $wpdb->last_result[0]->member_price; | |
$price_type = $wpdb->last_result[0]->member_price_type; | |
}else{ | |
$event_cost = $wpdb->last_result[0]->event_cost; | |
$price_type = $wpdb->last_result[0]->price_type; | |
} | |
$html .= '<p>' . $price_type . ' ' . $org_options['currency_symbol'] . number_format($event_cost, 2) . '</p>'; | |
} | |
echo $html; | |
return; | |
} | |
} | |
add_action('action_hook_espresso_price_list', 'event_espresso_price_list', 20, 2); |
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
//Just add this line of code wherever you want the list if prices to display (most likely in your wp-content/uploads/espresso/templates/event_list_display.php file): | |
<?php do_action('action_hook_espresso_price_list', $event_id);?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment