Support

Home Forums Event Espresso Premium Available Spaces in EE4

Available Spaces in EE4

Posted: March 6, 2015 at 9:53 am


awolf

March 6, 2015 at 9:53 am

My client wants to show available spaces for an upcoming event. I think in EE3 it used to show by default, but now we are using EE4 and I cannot find a way to add it. Can you assist? Thanks!


Lorenzo Orlando Caum

  • Support Staff

March 6, 2015 at 10:06 am

Hi there,

Event Espresso 4 works a little differently since it supports multiple ticket / pricing options. That information should be available when you click on the show tickets link (grey link) in the ticket selector:

http://cl.ly/image/1z082b422Q0R


Lorenzo


awolf

March 9, 2015 at 8:30 am

Is there a way to set a “total” tickets amount and show that? We have member tickets and non-member tickets, but we want to set the total number of spaces (regardless of ticket type). How is this accomplished and how to we show the number on the front end?


Lorenzo Orlando Caum

  • Support Staff

March 9, 2015 at 2:26 pm

Hi, would something like this work for you?

http://cl.ly/image/0W273W2Z0K3q

If so, then see this tutorial:

https://gist.github.com/joshfeck/0e2e59c39a36b76cc65a3b92f9543c79


Lorenzo


awolf

March 9, 2015 at 4:26 pm

Sorry. No that’s not what we are looking for. Let me try to explain better. We have an event – there are 15 total spaces available, but 2 prices (ticket options) for that event – one ticket price for members and one ticket price for non-members. Regardless of which ticket type a registrant chooses, we want them to take up one of the 15 available spaces, but we don’t know how many members and how many non-members will register so we want an overall limit, not a limit per ticket type. We also want to show the total available spaces on our registration page. Is that possible?


Dean

March 10, 2015 at 4:22 am

Hi,

Capacity in EE4 is set in two places: the datetimes and the tickets.

So if you have two tickets, you can apply them to one datetime, and set the ticket limits both to 15 and the datetime limit to 15.

This means that when someone buys a ticket it reduces both the ticket capacity and the datetime and when the datetime fills up that’s it, no more tickets can be sold for that datetime. So you could sell 15 of ticket A or 7 of A and 8 of B and both those situations would then stop ticket sales.

It’s a little bit more complex than in EE3, but I think you can see that it is much more flexible.

Regarding the capacity, this is already shown in the ticket details area: http://take.ms/eKcIm


awolf

March 10, 2015 at 7:36 am

We have a number set for the date/time (15) BUT it’s not showing on the front end. Please tell me how to get it to show up for the web visitor.


Lorenzo Orlando Caum

  • Support Staff

March 10, 2015 at 11:14 am

Okay, where on that page are you wanting to add that information? It would need to be near the ticket selector.

Thanks


Lorenzo


awolf

March 10, 2015 at 3:19 pm

It can be placed where ever it is easiest to add… we just want to display the available spots left somewhere on the event info page…


Dean

March 11, 2015 at 4:07 am

Hi,

I got to thinking and searching regarding this. We don’t currently have a way to display Available Spaces outside of the Ticket Selector.

Another customer, Paul Burwell, came up with some code that could do this.

I took this and modified it a bit as it wasn’t functioning in it’s current state and created a shortcode from it that will list each datetime and output the remaining spaces.

It’s only a basic example and could be built upon for more exact needs.

CODE
(I’ve requested this to be added to our snippet library (https://github.com/eventespresso/ee-code-snippet-library) but it’s awaiting acceptance at the moment of writing.

<?php
// Do not include the above opening PHP bracket unless this is at the start of the file
// The following function can be added to a themes functions.php file or a
// site specific plugin (https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/)
// to call the shortcode use [show_capacity] in any EVENT (it won't work outside of an event post)

/**
*   Original code, props to Paul Burwell
*   https://eventespresso.com/topic/help-showing-capacity/page/5/
*   Updated and modified by Dean Robinson 10th March 2015
**/

function my_print_tickets_left_after_selector($atts) {
    global $wpdb;

    $EVT_ID = get_the_ID();

    //display a title
    $x = '<h4>Remaining spaces</h4>';
    $x .= '<ul style="margin-left:0;">';

        $sql = "SELECT * ";
        $sql .= "FROM {$wpdb->prefix}esp_datetime ";
        $sql .= "WHERE {$wpdb->prefix}esp_datetime.EVT_ID = %d";
         
        $datetimes = $wpdb->get_results( $wpdb->prepare( $sql, $EVT_ID ));
         
        $dt_frmt = get_option('date_format');

        //echo "<pre>" . print_r($datetimes,1) . "</pre>";

        foreach($datetimes as $datetime){
            //display as a list
            $x .= "<li>";
            //if datetime name shown, display
            $name = !empty($datetime->DTT_name) ? ($datetime->DTT_name) . ': ' : date($dt_frmt, strtotime($datetime->DTT_EVT_start) ) . ': ';
            $x .= $name;

            $limit = $datetime->DTT_reg_limit;
            $sold = $datetime->DTT_sold;
            $remainderp = $limit - $sold;
            $remain = $limit == -1 ? '' : $remainderp;
            if ( $limit == $sold ) :
                $x .= '<strong>Sold Out</strong>';
            else :
                $x .= $remain;
            endif;
            $x .= "</li>";
        }
    $x .= '</ul>';
 
    return $x;
 
}
add_shortcode('show_capacity','my_print_tickets_left_after_selector');


awolf

March 11, 2015 at 7:37 am

Dean,

Thank you! That does the trick. One more quick question – can this be easily tweaked to just say: Remaining Spaces for this Camp: ## – instead of doing a list with the date? I realize with multiple event times it’s nice to have the list option, but it’s redundant and confusing for us with just one date per camp… Thanks!!


Tony

  • Support Staff

March 11, 2015 at 9:05 am

To do that you don’t need most of the code within the snippet Dean provided.

You can use something like this:

function my_print_tickets_left_after_selector($atts) {
    global $wpdb;

    $EVT_ID = get_the_ID();

    	$x = 'Remaining Spaces for this Camp: ';

        $sql = "SELECT * ";
        $sql .= "FROM {$wpdb->prefix}esp_datetime ";
        $sql .= "WHERE {$wpdb->prefix}esp_datetime.EVT_ID = %d";
         
        $datetimes = $wpdb->get_results( $wpdb->prepare( $sql, $EVT_ID ));
        
        $remaintotal = 0;

        foreach($datetimes as $datetime){
            $limit = $datetime->DTT_reg_limit;
            $sold = $datetime->DTT_sold;
            $remaintotal += $limit - $sold;
            $remain = $limit == -1 ? '' : $remaintotal;
        }

        $x .= $remain;
 
    return $x;
 
}
add_shortcode('show_capacity','my_print_tickets_left_after_selector');

Which will display ‘Remaining Spaces for this Camp: 99’ (99 being an example)

If you do happen to have multiple datetimes within an event, it will add the remaining spaces from each datetime to a total and display that total. This may not work as expected if tickets apply to multiple datetimes but if you are only using 1 it won’t matter, I added it in just to catch multiple datetimes.


awolf

March 11, 2015 at 9:34 am

The new code output an array string at the beginning of the event – Array ( [0] => stdClass Object ( [DTT_ID] => 1 [EVT_ID] => 3170 [DTT_name] => [DTT_description] => [DTT_EVT_start] => 2015-06-15 14:00:00 [DTT_EVT_end] => 2015-06-17 19:00:00 [DTT_reg_limit] => 15 [DTT_sold] => 0 [DTT_is_primary] => 0 [DTT_order] => 1 [DTT_parent] => 0 [DTT_deleted] => 0 ) )
Array ( [0] => stdClass Object ( [DTT_ID] => 1 [EVT_ID] => 3170 [DTT_name] => [DTT_description] => [DTT_EVT_start] => 2015-06-15 14:00:00 [DTT_EVT_end] => 2015-06-17 19:00:00 [DTT_reg_limit] => 15 [DTT_sold] => 0 [DTT_is_primary] => 0 [DTT_order] => 1 [DTT_parent] => 0 [DTT_deleted] => 0 ) )

I’ve modified the original code to this and it seems to work (note I am no coder, so this was just troubleshooting to remove or comment out the things I didn’t think I needed):

function my_print_tickets_left_after_selector($atts) {
global $wpdb;

$EVT_ID = get_the_ID();

//display a title
$x = ‘<p>Remaining Spaces for this Camp:’;
$x .= ‘ ‘;

$sql = “SELECT * “;
$sql .= “FROM {$wpdb->prefix}esp_datetime “;
$sql .= “WHERE {$wpdb->prefix}esp_datetime.EVT_ID = %d”;

$datetimes = $wpdb->get_results( $wpdb->prepare( $sql, $EVT_ID ));

$dt_frmt = get_option(‘date_format’);

//echo “

" . print_r($datetimes,1) . "

“;

foreach($datetimes as $datetime){
//display as a list
//$x .= “

  • “;
    //if datetime name shown, display
    //$name = !empty($datetime->DTT_name) ? ($datetime->DTT_name) . ‘: ‘ : date($dt_frmt, strtotime($datetime->DTT_EVT_start) ) . ‘: ‘;
    //$x .= $name;

    $limit = $datetime->DTT_reg_limit;
    $sold = $datetime->DTT_sold;
    $remainderp = $limit – $sold;
    $remain = $limit == -1 ? ” : $remainderp;
    if ( $limit == $sold ) :
    $x .= ‘Sold Out‘;
    else :
    $x .= $remain;
    endif;
    $x .= “</p>”;
    }
    $x .= ”;

    return $x;

    }
    add_shortcode(‘show_capacity’,’my_print_tickets_left_after_selector’);


  • Tony

    • Support Staff

    March 11, 2015 at 9:42 am

    Yes it’s the print_r() function wrapped in PRE tags that cause that. Commenting it out or removing it completely is fine.

    I actually removed it from my reply right after adding it to the thread but you must have loaded the page before then 🙂


    awolf

    March 11, 2015 at 4:11 pm

    Thank you so much for your help. We can mark this ticket as resolved.

    The support post ‘Available Spaces in EE4’ 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