/event_espresso_price_range.php Secret
Last active
December 18, 2015 12:18
-
-
Save Apina/49b614dbbb5e5efea65d 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. | |
function espresso_price_range($event_id, $text = '—') { | |
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); |
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 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