Support

Home Forums Event Espresso Premium EE4 – Displaying number of tickets available

EE4 – Displaying number of tickets available

Posted: June 24, 2014 at 4:46 pm

Viewing 12 reply threads


Chris Stambaugh

June 24, 2014 at 4:46 pm

Hi,

How can I display the number of tickets available for a particular event?

Thanks,

Paul


Dean

June 24, 2014 at 11:33 pm

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.


Chris Stambaugh

June 25, 2014 at 7:52 am

Might I suggest that this would be an _extremely_ useful bit of shortcode to be available in a future update?

Thanks,

Paul


Lorenzo Orlando Caum

  • Support Staff

June 25, 2014 at 11:52 am

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


Chris Stambaugh

June 25, 2014 at 11:59 am

Lorenzo,

Thanks for that. Where would I add that code on my WP site?

Paul


Josh

  • Support Staff

June 25, 2014 at 2:26 pm

Hi Paul,

We recommend adding this type of code into a site functionality plugin. The theme’s functions.php file will work as well.


Chris Stambaugh

June 26, 2014 at 12:17 pm

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


Josh

  • Support Staff

June 26, 2014 at 3:36 pm

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:

https://eventespresso.com/topic/customise-the-ticket_selector_chart-template-php-file-in-ee4/#post-92997

Alternatively, the extra information that you don’t want can be hidden with the CSS display:none; rule.


Chris Stambaugh

June 27, 2014 at 10:59 am

Okay, dumb question, how do I invoke this from my WP page?

Thanks,

Paul


Josh

  • Support Staff

June 27, 2014 at 12:13 pm

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


Chris Stambaugh

June 27, 2014 at 1:56 pm

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


Dean

June 30, 2014 at 2:05 am

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]


Chris Stambaugh

June 30, 2014 at 11:42 am

Dean,

Simply superb! Exactly what I was hoping/looking for.

Thanks a ton!

Paul

Viewing 12 reply threads

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.

Event Espresso