Support

Home Forums Event Espresso Premium Shortcode – ESPRESSO_EVENTS

Shortcode – ESPRESSO_EVENTS

Posted: June 4, 2020 at 5:18 am


dee4dogs

June 4, 2020 at 5:18 am

Is there a way with the ESPRESSO_EVENTS shortcode to filter out sold out events?

I can’t see anything here –
https://eventespresso.com/wiki/ee4-shortcodes-template-variables/


Tony

  • Support Staff

June 5, 2020 at 7:31 am

Hi Dee,

We don’t currently have a shortcode parameter for this.

We do have a snippet of code that can do this here:

https://eventespresso.com/topic/ee4-hide-sold-out-events-from-espresso_events-category_slug-page/

That would remove the events from all listings on the site, will that work for you?


dee4dogs

June 10, 2020 at 6:41 am

I’ve had that snippet in a plugin for a few years now (with this modification – https://eventespresso.com/topic/ee4-hide-sold-out-events-from-espresso_events-category_slug-page/#post-160482 ) . It’s working perfectly for the calendar, and the upcoming events widget…. but not for the ESPRESSO_EVENTS shortcode?


Tony

  • Support Staff

June 11, 2020 at 6:58 am

That snippet should apply to the ESPRESSO_EVENTS shortcode.

How are you adding that shortcode to the page? Using a page builder?

Can you post the full snippet you are using so I can test it locally?


dee4dogs

June 11, 2020 at 9:47 am

The shortcode is added using the standard WordPress page editor. No page builders or anything like that. It’s in a Paragraph block by itself.

The HTML view shows:
<p class="has-text-align-center">[ESPRESSO_EVENTS title="Upcoming Online Courses" category_slug=puppyschool-online]</p>

The Snippet is:

/*
REMOVE SOLD OUT & EXPIRED EVENTS FROM THE LISTINGS
*/

/**
 * The purpose of this snippet is to filter the event archive (and event taxonomy archive) pages so that they exclude events
 * that have tickets no longer on sale.
 *
 *  NOTE: This query is only valid for Event Espresso 4.8+
 *
 */
function de_ee_tweak_event_list_exclude_ticket_expired_events_where( $SQL, WP_Query $wp_query ) {
	if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events'  || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) {
		$SQL .= ' AND Ticket.TKT_sold < Ticket.TKT_qty AND Ticket.TKT_deleted=0 ';
	}
	return $SQL;
}
add_filter( 'posts_where', 'de_ee_tweak_event_list_exclude_ticket_expired_events_where', 15, 2 );
function de_ee_tweak_event_list_exclude_ticket_expired_events_join( $SQL, $wp_query ) {
	if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events'  || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) {
		if ( ! $wp_query->is_espresso_event_archive && ! $wp_query->is_espresso_event_taxonomy  ) {
			$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() . '.ID = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name() . ' ) ';
		}
		$SQL .= ' INNER JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' AS Datetime_Ticket ON ( Datetime_Ticket.DTT_ID=' . EEM_Datetime::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() . ' ) INNER JOIN ' . EEM_Ticket::instance()->table()  . ' AS Ticket ON ( Datetime_Ticket.TKT_ID=Ticket.' . EEM_Ticket::instance()->primary_key_name() . ' ) ';
	}
	return $SQL;
}
add_filter( 'posts_join', 'de_ee_tweak_event_list_exclude_ticket_expired_events_join', 3, 2 );


dee4dogs

June 11, 2020 at 9:50 am

The shortcode displays at the bottom of the front page

https://www.dee4dogs.co.uk/

You’ll see there’s a “Sold Out” event which shouldn’t be visible (and doesn’t appear in the widget or the calendar in the sidebar), and the upcoming Wednesday event which should be displaying.


Tony

  • Support Staff

June 11, 2020 at 3:05 pm

Was there only a single ticket on that event?

Also, does the ‘sold’ value match the limit set on the ticket?

The snippet doesn’t specifically check for an Event Post status, it’s checking the TKT_sold value is less than the TKT_qty value (meaning it’s pulling events where the ticket it’s using aren’t sold out) on a ticket within the event.


Tony

  • Support Staff

June 11, 2020 at 3:05 pm

Note that the snippet works locally for me: https://monosnap.com/file/mVYmHtAUEcow441yQJvwsUEQ2K9iS9

Thats just a page with [ESPRESSO_EVENTS]


dee4dogs

June 12, 2020 at 12:14 am

On that event there were four tickets, only one sold. So the “Sold Out” status was set manually.

So, if I understand correctly, the shortcode is just looking to include for events where tickets are still available…

I was thinking it was displaying all events, and then snippet was excluding sold-out and expired events. This is incorrect.

Is it possible to change the snippet to not display “Sold Out” status events (regardless of ticket sales)?

Thanks for the support.


Tony

  • Support Staff

June 19, 2020 at 7:03 am

It makes the query a little bit odd, but try something like this:

https://gist.github.com/Pebblo/285340c950796e16eae8ba1d2e520513

You would use that function in place of the 2 used previously.

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3 Documentation for Event Espresso 4

Status: publish

Updated by  Tony 3 months, 2 weeks ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!
[gravityform id=80 title=false description=false ajax=false]
<div class='gf_browser_unknown gform_wrapper' id='gform_wrapper_80' ><form method='post' enctype='multipart/form-data' id='gform_80' action='/topic/shortcode-espresso_events/'> <div class='gform_body'><ul id='gform_fields_80' class='gform_fields top_label form_sublabel_below description_below'><li id='field_80_1' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_1' >First name<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_text'><input name='input_1' id='input_80_1' type='text' value='' class='medium' aria-required="true" aria-invalid="false" /></div></li><li id='field_80_2' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_2' >Email address<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_email'> <input name='input_2' id='input_80_2' type='email' value='' class='medium' aria-required="true" aria-invalid="false" /> </div></li><li id='field_80_3' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' >GDPR Agreement<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_checkbox'><ul class='gfield_checkbox' id='input_80_3'><li class='gchoice_80_3_1'> <input name='input_3.1' type='checkbox' value='I consent to have this website store my submitted information so they can respond to my inquiry.' id='choice_80_3_1' /> <label for='choice_80_3_1' id='label_80_3_1'>I consent to have this website store my submitted information so they can respond to my inquiry.</label> </li></ul></div></li><li id='field_80_4' class='gfield gform_validation_container field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_4' >Email</label><div class='ginput_container'><input name='input_4' id='input_80_4' type='text' value='' autocomplete='off'/></div><div class='gfield_description' id='gfield_description_80_4'>This field is for validation purposes and should be left unchanged.</div></li> </ul></div> <div class='gform_footer top_label'> <input type='submit' id='gform_submit_button_80' class='gform_button button' value='Download Now' onclick='if(window["gf_submitting_80"]){return false;} if( !jQuery("#gform_80")[0].checkValidity || jQuery("#gform_80")[0].checkValidity()){window["gf_submitting_80"]=true;} ' onkeypress='if( event.keyCode == 13 ){ if(window["gf_submitting_80"]){return false;} if( !jQuery("#gform_80")[0].checkValidity || jQuery("#gform_80")[0].checkValidity()){window["gf_submitting_80"]=true;} jQuery("#gform_80").trigger("submit",[true]); }' /> <input type='hidden' class='gform_hidden' name='is_submit_80' value='1' /> <input type='hidden' class='gform_hidden' name='gform_submit' value='80' /> <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' /> <input type='hidden' class='gform_hidden' name='state_80' value='WyJbXSIsIjBiNjdjZjkyMDUzOWUxOWY5Y2NiZjIwMzM4YjA1Mjk4Il0=' /> <input type='hidden' class='gform_hidden' name='gform_target_page_number_80' id='gform_target_page_number_80' value='0' /> <input type='hidden' class='gform_hidden' name='gform_source_page_number_80' id='gform_source_page_number_80' value='1' /> <input type='hidden' name='gform_field_values' value='' /> </div> </form> </div><script type='text/javascript'> jQuery(document).bind('gform_post_render', function(event, formId, currentPage){if(formId == 80) {} } );jQuery(document).bind('gform_post_conditional_logic', function(event, formId, fields, isInit){} );</script><script type='text/javascript'> jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [80, 1]) } ); </script>
[i]
[i]