Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Displays a list of prices if there are multiple prices per event. Otherwise it just shows a single price.
<?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);
//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);?>
@sethshoultes

This comment has been minimized.

Copy link
Owner Author

@sethshoultes sethshoultes commented Feb 19, 2013

Final result:

  • Members Admission ($0.00)
  • Members Admission ($1.00)
  • Members Admission ($7.95)

Code Example:
http://www.screencast.com/t/vPLTPE5ig

Example of the final results in the event list:
http://www.screencast.com/t/aF1DcStsKH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.