Support

Home Forums Event Espresso Premium How to display a custom message only for free & upcoming events

How to display a custom message only for free & upcoming events

Posted: July 14, 2015 at 1:14 pm

Viewing 4 reply threads


Deborah Fox

July 14, 2015 at 1:14 pm

I’ve added the following into my site-specific plug-in to display a message about registration:

add_action( ‘AHEE_event_details_after_event_date’, ‘ee_custom_messaging_after_event_details’ );
function ee_custom_messaging_after_event_details() {
echo ‘I am super genius. ‘;
}

How can I make this message only display on events that are free and upcoming?


Dean

July 15, 2015 at 3:53 am

Hi,

So, that action hook comes with the $post variable.

You can use this, in conjunction with the various EE Classes to get what you need:

add_action( 'AHEE_event_details_after_event_date', 'ee_custom_messaging_after_event_details' );

function ee_custom_messaging_after_event_details($post) {

  //let's make sure it's upcoming
  //See EE_Event class in /wp-content/plugins/event-espresso-core-reg/core/db_classes/EE_Event.class.php
  $active = $post->EE_Event->is_upcoming();

  //for later
  $price_check = '';

  if( $active ) {
    //if upcoming, get the events tickets
    ///wp-content/plugins/event-espresso-core-reg/core/db_classes/EE_Event.class.php
    $tickets = $post->EE_Event->tickets($query_params = array());

    //check each ticket to see if free (zero cost) if not add a flag to $price_check.
// once we assign the tickets to the variable we can use the EE_Ticket class
//add_action( 'AHEE_event_details_after_event_date', 'ee_custom_messaging_after_event_details' );

function ee_custom_messaging_after_event_details($post) {

  //let's make sure it's upcoming
  //See EE_Event class in /wp-content/plugins/event-espresso-core-reg/core/db_classes/EE_Event.class.php
  $active = $post->EE_Event->is_upcoming();

  //for later
  $price_check = '';

  if( $active ) {
    //if upcoming, get the events tickets
    ///wp-content/plugins/event-espresso-core-reg/core/db_classes/EE_Event.class.php
    $tickets = $post->EE_Event->tickets($query_params = array());

    //check each ticket to see if free (zero cost) if not add a flag to $price_check.
    foreach ($tickets as $ticket) {

      $price = $ticket->ticket_price();

      if ( $price !== (float)0 ) {
        $price_check = 'notfree';
      }

    }

  }
  else {
    //if not upcmoing, just return
    return;
  }

  //check the $price_check variable for the flag. If it does NOT exist (no tickets with a price higher than zero) then output a message
  if( $price_check != 'notfree' ) {
    echo 'I am super genius.';
  }

}
    foreach ($tickets as $ticket) {

      $price = $ticket->ticket_price();

      if ( $price !== (float)0 ) {
        $price_check = 'notfree';
      }

    }

  }
  else {
    //if not upcmoing, just return
    return;
  }

  //check the $price_check variable for the flag. If it does NOT exist (no tickets with a price higher than zero) then output a message
  if( $price_check != 'notfree' ) {
    echo 'I am super genius.';
  }

}

That should get you started.


Deborah Fox

July 15, 2015 at 8:22 am

Thank you, Dean. I hadn’t realized this would be so involved & appreciate your help. However, when I add this to my plugin the message is being removed from all events. To simplify things, I’ve tried eliminating the price variable and have instead just tried to get the message only displaying on upcoming events. I’m not having any luck — I either get it posted on all events, or none. Could you please tell me how to edit this down?


Dean

July 16, 2015 at 4:18 am

Hi,

Yes it can be a little more complex, as the code behind EE4 is quite complex.

It is set up so that if the event is upcoming and their are no paid for tickets, the message is displayed http://take.ms/IxwSt but if there is a paid for ticket it isn’t http://take.ms/tI2mf


Deborah Fox

July 16, 2015 at 1:22 pm

I still am unable to get it to work on my end, so decided to move the text to another location on the page. Thanks again for your help.

Viewing 4 reply threads

The support post ‘How to display a custom message only for free & upcoming events’ 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