Support

Home Forums Event Espresso Premium EE4 Hide sold out events from [ESPRESSO_EVENTS category_slug=""] page

EE4 Hide sold out events from [ESPRESSO_EVENTS category_slug=""] page

Posted: June 8, 2015 at 3:55 pm

Viewing 10 reply threads


Bob Randklev

June 8, 2015 at 3:55 pm

As our clients classes sell out we want to hide them or move them below the available events so visitors won’t have to scroll down each page.

I couldn’t find this in the wiki?


Josh

  • Support Staff

June 9, 2015 at 7:31 am

Hi Bob,

There’s some example code from Github that will remove any upcoming events that no longer have tickets for sale from the event list.

https://eventespresso.com/wiki/useful-php-code-snippets/#no-tickets-no-event-list

Please note that the code will affect all of the event lists. If you intend on only hiding the sold out events from your pages with shortcodes, you can wrap the code in a conditional check for those pages.


Bob Randklev

June 9, 2015 at 7:45 am

To clarify you are saying this link to GitHub:
https://github.com/eventespresso/ee-code-snippet-library/blob/master/templates/de_ee_filter_events_out_with_expired_tickets.php

I’m not sure expired tickets is what we want, this page shows a number of sold out events that haven’t started yet and people have to scroll down to find the next available event:

http://streetsmartsdriversed.com/iowa/marion/indian-creek-ind-classes/


Josh

  • Support Staff

June 9, 2015 at 8:54 am

Hi Bob,

It’s up to you if you want to remove the check for expired events from the example code. You can add a check for a sold out event condition by adding the following to the end of the SQL statement in the first function of the example code:

AND Ticket.TKT_sold < Ticket.TKT_qty


Bob Randklev

June 9, 2015 at 11:46 am

Thanks Josh but I’m not that good with code, I can copy paste 🙂

Which line or change do I make to the Github code?


Josh

  • Support Staff

June 9, 2015 at 1:02 pm

On line 15, where the first function has this:

$SQL .= ' AND Ticket.TKT_end_date > "' . current_time( 'mysql', true ) . '" AND Ticket.TKT_deleted=0';

You change it to this:

$SQL .= ' AND Ticket.TKT_sold < Ticket.TKT_qty AND Ticket.TKT_deleted=0 ';


Bob Randklev

June 9, 2015 at 1:28 pm

I tried that but it removes all events from the page.


Josh

  • Support Staff

June 9, 2015 at 1:42 pm

It may help if you can copy and paste the code that ended up in your functions file in a gist or pastebin and link here so we can make sure there were not any errors in the copy and pasting.

This is because I checked the code on a site before I shared it with you and it only removed the sold out events.

Aside from that, it may be quicker if this gets worked out with a priority support token since it’s a customization.


Bob Randklev

June 9, 2015 at 2:14 pm

Josh I’m using the code you referenced at GitHub

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_end_date > "' . current_time( 'mysql', true ) . '" 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 );

If you want to send me your entire code, and if it’s working on your site, I’ll use all the code vs a line here and there.

The above is the standard code without the edits we’ve been trying to make.

I’m surprised I’m the first person to ask about hiding sold out events?

Thanks for your help, we aren’t in any rush.


Josh

  • Support Staff

June 9, 2015 at 3:33 pm

Hi Bob,

Posting the code here doesn’t really help because our forum software is not designed to handle large blocks of code like this. There could be a single quote replaced by a curly quote, which would throw an error, but since you didn’t post to a pastebin or gist I can’t really tell. Are you using a code editor to edit the file?

Here’s a link to a gist that has the modified code. If you’re editing the PHP files with something like text edit, you might run into trouble with quotes getting converted to curly quotes. It may help to have a PHP developer look things over if you’re not sure.


Bob Randklev

June 10, 2015 at 7:50 am

Josh, I’m using Coda to edit the functions.php file

Thanks for posting the code but when I apply it same results, it blocks all classes.

Unfortunately I can’t leave it to have you view as they are taking registrations daily…

I can however setup a staging site in WPEngine and test there, then I’ll send you a link.. later today or tomorrow.

Viewing 10 reply threads

The support post ‘EE4 Hide sold out events from [ESPRESSO_EVENTS category_slug=""] page’ 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