Support

Home Forums Event Espresso Premium Custom message to appear when event full

Custom message to appear when event full

Posted: September 16, 2015 at 9:21 pm

Viewing 7 reply threads


Judy

September 16, 2015 at 9:21 pm

Hello.
I am curious how I can output a custom message when an event is full, like how in php i could echo that out.. something like <?php echo $event_full ?> but with a custom message I created.

Currently we have to manually go into the back end to set the course at a time before today to enable the word “Closed” to appear. Because when it’s full it doesn’t display a message.

Also,
I am using the a modified copy of the events table plugin, you can see what I have done with it here.. essentially, I need a message to appear in place of our add to cart button.


Tony

  • Support Staff

September 17, 2015 at 2:07 am

Hi Judy,

There is currently no link to view your current table, can you add that again please?

Are you using EE3 or EE4?

Looks like your site is currently in maintenance mode so we can’t view anything. Can you provide login details so we can take a look?

If so please send via this form:

https://eventespresso.com/send-login-details/


Judy

September 17, 2015 at 10:14 am

Sorry for the poor explanation Tony!

Currently, we use EE3.

Here is a look at our table display of events (classes)

https://dvsa.ca/classes/

We would like to have a custom message displayed in place of the “add to cart” link.

Currently, when an event becomes full – we have to manually go into the event and set it to a date before today in order for it to actually say “closed”
Is there a way we can make it say “Closed” or a message of our choice automatically once the event is full without having to go into the event and set it for a date before today?

Thanks kindly!


Josh

  • Support Staff

September 17, 2015 at 4:17 pm

Hi Judy,

This is possible, the first step is add some code that checks if the event is full, then do an if/else statement where it shows the sold out message or the cart link depending on if it’s full or not. Something like this:

<?php
if ( apply_filters('filter_hook_espresso_get_num_available_spaces', $event_id) == 0 ) {
	echo 'This event is sold out message';
} else {
	// add to cart link code goes here ;
}
?>


Judy

September 18, 2015 at 1:16 pm

Thanks Josh, I have tried your code and some different things with it, nothing seems to work.

Currently, I use this to output my cart link:

<?php echo $event_status == 'ACTIVE' ? $cart_link : $live_button; ?>

Combined with your code I’ve tried this

<?php
if ( apply_filters('filter_hook_espresso_get_num_available_spaces', $event_id) == 0 ) {
	echo 'This event is sold out message';
} else {
	echo $event_status == 'ACTIVE' ? $cart_link : $live_button;
}
?>

I’ve also attempted to fiddle with it as much as I can in attempt to get it to work, but no luck (not the best with php)

Perhaps you might spot an error in this file preventing it from working or mabye some more insight?

I conducted a few tests, mainly.. I’ve set max number of attendees to 1, registered and then checked the page to see if the message appears saying that it is full.. nothing shows..

take a look at my file here:

<?php /* ---- Default events-table template ---- */ ?>

  <div id="FilterContainer">

  		<div class="class-header hidden-sm hidden-xs" style="padding:0 0 15px 24px; margin-bottom:15px; border-bottom:1px solid #ddd; display:inline-block; width:100%;">	
	  		<div class="col-md-4">
	  			<strong>Class</strong>
	  		</div>

	  		<div class="col-md-2">
	  			<strong>Instructor</strong>
	  		</div>

	  		<div class="col-md-3">
	  			<strong>Date</strong>
	  		</div>

  		<div class="col-md-1">
	  			<strong>Cost</strong>
  		</div>

	  		<div class="col-md-2">
	  			<strong>Enroll</strong>
	  		</div>
  		</div>

		<?php

      foreach ($events as $event){
		$button_text 		= __('Register', 'event_espresso');
		$alt_button_text	= __('View Details', 'event_espresso');//For alternate registration pages
		$externalURL 		= $event->externalURL;
		$button_text		= !empty($externalURL) ? $alt_button_text : $button_text;
		$registration_url 	= !empty($externalURL) ? $externalURL : espresso_reg_url($event->id);
		if ( has_filter( 'filter_hook_espresso_get_num_available_spaces' ) ){
			$open_spots		= apply_filters('filter_hook_espresso_get_num_available_spaces', $event->id); //Available in 3.1.37
		}else{
			$open_spots		= get_number_of_attendees_reg_limit($event->id, 'number_available_spaces');
		}
		$live_button 		= '<a id="a_register_link-'.$event->id.'" href="'.$registration_url.'">'.$button_text.'</a>';
		$event_status 		= event_espresso_get_status($event->id);
		
		//Check for Multi Event Registration
		$multi_reg = false;
		if (function_exists('event_espresso_multi_reg_init')) {
			$multi_reg = true;
		}
		$cart_link 	= '';
		
		//Create an add to cart link
		if ($multi_reg && $event_status == 'ACTIVE' && empty($externalURL)) {
			$params = array(
				//REQUIRED, the id of the event that needs to be added to the cart
				'event_id' => $event->id,
				//REQUIRED, Anchor of the link, can use text or image
				'anchor' => __("Add to Cart", 'event_espresso'), //'anchor' => '<img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/cart_add.png" />',
				//REQUIRED, if not available at this point, use the next line before this array declaration
				// $event_name = get_event_field('event_name', EVENTS_DETAIL_TABLE, ' WHERE id = ' . $event_id);
				'event_name' => $event->event_name,
				'event_desc' => $event->event_desc,
				//OPTIONAL, will place this term before the link
				// 'separator' => ' '.__("or", 'event_espresso').' '

			);

			$cart_link = event_espresso_cart_link($params);
		}
		
		if($open_spots < 1 && $event->allow_overflow == 'N') {
			$live_button = __('Sold Out', 'event_espresso');
			$cart_link = '';
		} else if ($open_spots < 1 && $event->allow_overflow == 'Y'){
			$live_button = !empty($event->overflow_event_id) ? '<a href="'.espresso_reg_url($event->overflow_event_id).'">'.__('Join Waiting List', 'event_espresso').'</a>' : __('Sold Out', 'event_espresso');
			$cart_link = '';
		}
		
		if ($event_status == 'NOT_ACTIVE') { 
			$live_button = __('Closed', 'event_espresso');
			$cart_link = '';
		}

	   ?>

  	<div class="class-container all cat-<?php echo str_replace(',', ' cat-', $event->category_id); ?>" style="margin-bottom:5px; display:inline-block; width:100%;">

  			<style type="text/css">
  			.toggle {
  			  border-bottom: 1px solid #ddd;
			  display: block;
			  position: relative;
			  margin: 0 0 15px;
			  padding-bottom: 15px;
			  }
			 </style>
                        <div class="toggle">

                            <div class="togglet"><i class="toggle-closed icon-line-circle-plus"></i><i class="toggle-open icon-line-circle-cross"></i>

									<div class="col-md-4">
							  			<strong><?php echo stripslashes_deep($event->event_name) ?></strong>
							  		</div>

							  		<div class="col-md-2">
							  			<div class="hidden-lg hidden-md mobile-aid nobold" style="font-style: italic">with</div> <?php echo do_shortcode('[ESPRESSO_STAFF show_staff_roles="false" show_description="false" show_staff_details="false" event_id="' . $event->id . '"]'); ?>
							  		</div>

							  		<div class="col-md-3">
							  			<div class="hidden-lg hidden-md mobile-aid nobold">on</div> 
							  			<p class="class-date nomargin">

											<?php 
											//start date
											$sd = event_date_display($event->start_date, 'j M');
											//start date year
											$sdy = event_date_display($event->start_date, 'Y');
											//end date
											$ed = event_date_display($event->end_date, 'j M');
											//start time
											$st = event_date_display($event->start_time, get_option('time_format'));
											//end time
											$et = event_date_display($event->end_time, get_option('time_format'));

											//bring it all together

											echo $sd . ' - ' . $ed . ', ' . $sdy . ' from ' . $st . ' to ' . $et;

											?>

							  			</p>
							  		</div>

							  		<div class="col-md-1">
									$<?php echo $event->event_cost; ?>
							  		</div>

							  		<div class="col-md-2">

<?php
if ( apply_filters('filter_hook_espresso_get_num_available_spaces', $event_id) == 0 ) {
	echo 'This event is sold out message';
} else {
	echo $event_status == 'ACTIVE' ? $cart_link : $live_button;
}
?>

							  		
							  		</div>

                            </div>

                            <div class="togglec">

                         
										<div class="event-desc">
										
											<?php echo espresso_format_content($event->event_desc); ?>

										</div>
										

							</div>
                        </div>
  		

  	</div>

<?php } //close foreach ?>

</div>

<script type="text/javascript">
$("select.filterby").change(function(){
    var filters = $.map($("select.filterby").toArray(), function(e){
        return $(e).val();
    }).join(".");
    $("#FilterContainer").find(".class-container").hide();
    $("#FilterContainer").find(".class-container." + filters).show();
});
</script>

<div class="line clearfix"></div>
<!-- 
<table id="ee_filter_table_<?php echo $template_identifier; ?>" class="espresso-table" width="100%">
	<thead class="espresso-table-header-row">
		<tr>
			<th class="th-group"><?php _e('Event','event_espresso'); ?></th>
			<th class="th-group"><?php _e('Venue','event_espresso'); ?></th>
			<th class="th-group"><?php _e('Date','event_espresso'); ?></th>
			<th class="th-group"></th>
		</tr>
	</thead>
	<tbody>
		<?php

      foreach ($events as $event){
		$button_text 		= __('Register', 'event_espresso');
		$alt_button_text	= __('View Details', 'event_espresso');//For alternate registration pages
		$externalURL 		= $event->externalURL;
		$button_text		= !empty($externalURL) ? $alt_button_text : $button_text;
		$registration_url 	= !empty($externalURL) ? $externalURL : espresso_reg_url($event->id);
		if ( has_filter( 'filter_hook_espresso_get_num_available_spaces' ) ){
			$open_spots		= apply_filters('filter_hook_espresso_get_num_available_spaces', $event->id); //Available in 3.1.37
		}else{
			$open_spots		= get_number_of_attendees_reg_limit($event->id, 'number_available_spaces');
		}
		$live_button 		= '<a id="a_register_link-'.$event->id.'" href="'.$registration_url.'">'.$button_text.'</a>';
		$event_status 		= event_espresso_get_status($event->id);
		
		//Check for Multi Event Registration
		$multi_reg = false;
		if (function_exists('event_espresso_multi_reg_init')) {
			$multi_reg = true;
		}
		$cart_link 	= '';
		
		//Create an add to cart link
		if ($multi_reg && $event_status == 'ACTIVE' && empty($externalURL)) {
			$params = array(
				//REQUIRED, the id of the event that needs to be added to the cart
				'event_id' => $event->id,
				//REQUIRED, Anchor of the link, can use text or image
				'anchor' => __("Add to Cart", 'event_espresso'), //'anchor' => '<img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/cart_add.png" />',
				//REQUIRED, if not available at this point, use the next line before this array declaration
				// $event_name = get_event_field('event_name', EVENTS_DETAIL_TABLE, ' WHERE id = ' . $event_id);
				'event_name' => $event->event_name,
				//OPTIONAL, will place this term before the link
				'separator' => ' '.__("or", 'event_espresso').' '
			);

			$cart_link = event_espresso_cart_link($params);
		}
		
		if($open_spots < 1 && $event->allow_overflow == 'N') {
			$live_button = __('Sold Out', 'event_espresso');
			$cart_link = '';
		} else if ($open_spots < 1 && $event->allow_overflow == 'Y'){
			$live_button = !empty($event->overflow_event_id) ? '<a href="'.espresso_reg_url($event->overflow_event_id).'">'.__('Join Waiting List', 'event_espresso').'</a>' : __('Sold Out', 'event_espresso');
			$cart_link = '';
		}
		
		if ($event_status == 'NOT_ACTIVE') { 
			$live_button = __('Closed', 'event_espresso');
			$cart_link = '';
		}

	   ?>
		<tr class="espresso-table-row all cat-<?php echo str_replace(',', ' cat-', $event->category_id); ?>">
			<td class="event_title event-<?php echo $event->id;?>"><?php echo stripslashes_deep($event->event_name) ?></td>
			<td class="venue_title venue-<?php echo $event->id;?>"><?php echo stripslashes($event->venue_name) ?></td>
			<td class="start_date start_date-<?php echo $event->id;?>"><?php echo event_date_display($event->start_date/*.' '.$event->start_time, get_option('date_format').' '.get_option('time_format')*/) ?></td>
			<td class="td-group reg-col" nowrap="nowrap"><?php echo $event_status == 'ACTIVE' ? $live_button .  $cart_link : $live_button; ?></td>
		</tr>
		<?php } //close foreach ?>
	</tbody>
</table>
 -->


Josh

  • Support Staff

September 18, 2015 at 1:37 pm

Hi Judy,

It looks like it’s the event ID variable. I kind of assumed that $event_id would be set, but it’s not set in your template. This will work instead:

<?php
if ( apply_filters('filter_hook_espresso_get_num_available_spaces', $event->id) == 0 ) {
	echo 'This event is sold out message';
} else {
	echo $event_status == 'ACTIVE' ? $cart_link : $live_button;
}
?>

The change is in how it gets the ID, in my original example it had $event_id, and you’ll change it to use $event->id instead.


Judy

September 18, 2015 at 2:08 pm

This worked perfectly,
Thank you so much for your time!


Josh

  • Support Staff

September 18, 2015 at 2:17 pm

You’re welcome Judy.

Viewing 7 reply threads

The support post ‘Custom message to appear when event full’ 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