Skip to content

Instantly share code, notes, and snippets.

@Apina
Forked from sethshoultes/event_espresso_price_range.php
Last active December 18, 2015 12:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Apina/49b614dbbb5e5efea65d to your computer and use it in GitHub Desktop.
Save Apina/49b614dbbb5e5efea65d to your computer and use it in GitHub Desktop.
No longer valid - EE3 now supports this in the Template options.
<?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