Posted: June 24, 2014 at 4:46 pm
|
Hi, How can I display the number of tickets available for a particular event? Thanks, Paul |
|
Hi Paul, The ticket capacity is part of the ticket details section (hidden until you click the “show details” link on the ticket itself). Unlike EE3, there is no specific shortcode to pull out the available tickets. |
|
Might I suggest that this would be an _extremely_ useful bit of shortcode to be available in a future update? Thanks, Paul |
Thanks for sharing that insight. You can trigger the ticket selector to expand on a page load by using something like this: function ee_ticket_selector_show_details() { ?> <script type="text/javascript"> jQuery(document).ready(function () { setTimeout(function() { jQuery(".display-tckt-slctr-tkt-details").trigger('click'); },5); }); </script> <?php } add_action( 'wp_footer', 'ee_ticket_selector_show_details' ); That would make the ticket details available to attendees/registrants. — |
|
|
Lorenzo, Thanks for that. Where would I add that code on my WP site? Paul |
Hi Paul, We recommend adding this type of code into a site functionality plugin. The theme’s functions.php file will work as well. |
|
|
The thing is I don’t need all of the event details, just the quantity of tickets remaining. Any way of making this happen? Paul |
More than one way. One way would be to remove the unwanted elements from the ticket selector table template. The name of the file that handles this is ticket_selector_chart.template.php. It turns out there’s a filter that makes it possible to load your custom template from your theme or another location. I posted a few code examples on how to load a customized ticket_selector_chart.template.php file here: Alternatively, the extra information that you don’t want can be hidden with the CSS display:none; rule. |
|
|
Okay, dumb question, how do I invoke this from my WP page? Thanks, Paul |
Hi Paul, It’s not a dumb question, and the answer is you don’t. This is the kind of thing that involves copying files and modifying them using a text editor and an FTP client. -or- if you go the CSS route your WordPress theme might have a custom stylesheet where you can add your custom CSS to. -or- as another option if you have a custom snippets plugin set up, you can add to and adapt this code snippet to get what you’re after: https://eventespresso.com/wiki/useful-php-code-snippets/#tickets-left |
|
|
Josh, Thanks for the code. I’m sure it will be useful, once I figure out one more step. On a page like this: http://www.bsop.ca/edmonton-digital-camera-fundamentals-photography-classes/ I want to add another column to the table at the top of the screen that shows quantity remaining. I’m using table press and each row links to a page for the particular event which in term invokes the event registration code for the particular event. What HTML would I add to the table press row to show the quantity available from the function you provided? Thanks again, Paul |
|
Hi Paul, The only way to do that would be to modify the function and turn it into a shortcode, then you can add the shortcode to the Tablepress field. function my_print_tickets_left_after_selector($atts) { global $wpdb; $EVT_ID = $atts['evt_id']; $x = ''; $x .= '<ul style="margin-left:0;">'; $sql = "SELECT DTT_name, DTT_reg_limit, DTT_sold "; $sql .= "FROM {$wpdb->prefix}esp_datetime "; $sql .= "WHERE {$wpdb->prefix}esp_datetime.EVT_ID = %d"; $datetimes = $wpdb->get_results( $wpdb->prepare( $sql, $EVT_ID )); foreach($datetimes as $datetime){ $name = !empty($datetime->DTT_name) ? ($datetime->DTT_name) : 'this event'; $limit = $datetime->DTT_reg_limit; $sold = $datetime->DTT_sold; $remainderp = $limit - $sold; $remain = $limit == -1 ? 'bucketloads of' : $remainderp; if ( $limit == $sold ) : $x .= $name . ' is <b>sold out</b>'; else : $x .= sprintf( _nx( '%1$sThere is one space left for %3$s</li>', '%1$sThere are %2$s spaces left for %3$s</li>', $remain, 'event ticket info', 'event_espresso' ), '<li style="list-style-type:none;">', $remain, '<span>' . $name . '</span>' ); endif; } $x .= '</ul>'; return $x; } add_shortcode('show_capacity','my_print_tickets_left_after_selector'); [show_capacity EVT_ID=83] |
|
Dean, Simply superb! Exactly what I was hoping/looking for. Thanks a ton! Paul |
The support post ‘EE4 – Displaying number of tickets available’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.