-
-
Save Apina/d7e811c18ef6719aaf04 to your computer and use it in GitHub Desktop.
EE4 remaining spaces shortcode - PROOF OF CONCEPT. If you use this, please not it has not been fully tested nor is it supported by Event Espresso, it's merely a proof of concept and should be built upon with further development. To use, add the code to a custom functions plugin or to your themes functions.php and then add the shortcode [eeavaila…
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
function eefour_remaining_spaces_shortcode($atts) { | |
// PROOF OF CONCEPT | |
// | |
// Shortcode for EE4 that allows an evnt id to be inserted and the remaining number of tickets to be shown. | |
// | |
// This is not supported by Event Espresso and is only to be used as a basis for custom work as it may not | |
// be fully functional in certain use cases (it hasnt been tested in depth). | |
// | |
// As the data is separated, it requires 3+ DB calls | |
// can probs reduce this to max 3 by just pulling each table in it's entirety rather than specific rows and | |
// then playing with the data. | |
// USAGE | |
// | |
// add the following shortocde to a post or page. | |
// [eeavailablespaces event_id="1"] where 1 is the event id so change accordingly | |
global $wpdb; | |
$evt_id = $atts['event_id']; //post->ID; | |
//Call 1, get the current datetimes | |
$table_dt = $wpdb->prefix . 'esp_datetime'; | |
$dts = $wpdb->get_results("SELECT * FROM $table_dt WHERE EVT_ID = $evt_id"); | |
//var_dump($dts); | |
$the_dtt_id = $dts[0]->DTT_ID; | |
//Call 2 get the tickets associated with those data times | |
$table_dt_tckt = $wpdb->prefix . 'esp_datetime_ticket'; | |
$dt_tckt = $wpdb->get_results("SELECT * FROM $table_dt_tckt WHERE DTT_ID = $the_dtt_id"); | |
//var_dump($dt_tckt); | |
//Call 3 now get the actual tickets | |
$table_tckt = $wpdb->prefix . 'esp_ticket'; | |
$tickets = array(); | |
foreach ($dt_tckt as $ticket) { | |
$tckt_id = $ticket->TKT_ID; | |
$tickets[] = $wpdb->get_results("SELECT * FROM $table_tckt WHERE TKT_ID = $tckt_id AND TKT_deleted != 1"); | |
} | |
//var_dump($tickets); | |
$t_quant = 0; | |
$t_sold = 0; | |
foreach ($tickets as $ticket) { | |
$t_quant = $t_quant + $ticket[0]->TKT_qty; | |
$t_sold = $t_sold + $ticket[0]->TKT_sold; | |
} | |
$rem_spaces = $t_quant - $t_sold; | |
$return = '<div class="ee_remaining_spaces"><h2>' . __('Remaining Spaces') . '</h2>'; | |
$return .= '<span>' . $rem_spaces . '</span>'; | |
$return .= '</div>'; | |
return $return; | |
} | |
add_shortcode('eeavailablespaces', 'eefour_remaining_spaces_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment