Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Displays a range of prices, if there are multiple prices, per event. Otherwise it just shows a single price. Eg.: Price: $1.00 — $2.00
<?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.
function espresso_price_range($event_id, $text = '&mdash;') {
global $wpdb, $org_options;
$result = array("max" => 0, "min" => 0);
if (function_exists('espresso_members_version') && is_user_logged_in()) {
$price_field = "member_price";
} else {
$price_field = "event_cost";
}
$sql = "SELECT MIN(ep.{$price_field}) AS min_price, MAX(ep.{$price_field}) AS max_price FROM " . EVENTS_PRICES_TABLE . " ep INNER JOIN " . EVENTS_PRICES_TABLE . " ep2 ON ep.event_id = ep2.event_id WHERE ep2.event_id = $event_id ";
$price_row = $wpdb->get_row($sql);
if ($price_row !== NULL) {
$result['min'] = $price_row->min_price;
$result['max'] = $price_row->max_price;
} else {
echo $org_options['currency_symbol'].'0.00';
return;
}
if ($result['min'] == $result['max']) {
$result = $org_options['currency_symbol'].$result['min'];
} else {
$result = $org_options['currency_symbol'].$result['min'] . " $text " . $org_options['currency_symbol'].$result['max'];
}
echo $result;
}
add_action('action_hook_espresso_price_range', 'espresso_price_range', 20, 2);
//Just add this line of code wherever you want the price range to display (most likely in your wp-content/uploads/espresso/templates/event_list_display.php file):
<?php do_action('action_hook_espresso_price_range', $event_id);?>
//Example:
<p id="p_event_price-<?php echo $event_id ?>" class="event_price"><span class="section-title"><?php echo __('Price: ', 'event_espresso'); ?></span> <?php do_action('action_hook_espresso_price_range', $event_id); ?></p>
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.