Support

Home Forums Event Espresso Premium Change Button Text If Event Is Free

Change Button Text If Event Is Free

Posted: November 3, 2016 at 11:20 am

Viewing 3 reply threads


dlamunyon

November 3, 2016 at 11:20 am

We want our template to check and see if an event is free. If it is free, the button/link text would say “Register”. If it’s not free, it would display the regular “Buy Tickets Now”.

I added this to the top of our template…
$free_button_text = !isset($free_button_text) ? __('Register', 'event_espresso') : $free_button_text;//For free events

and then I tried to add an ‘If’ statement to check if the event is free…

								if($event->event_cost === "0.00") {
								 ?><a id="a_register_link-<?php echo $post->ID; ?>" href="<?php echo $registration_url; ?>"><?php echo '<b class="home-display-button-text">' . $free_button_text . '</b>'?></a><?php ;
								}else {
								echo '<b>'; ?>
								<a id="a_register_link-<?php echo $post->ID; ?>" href="<?php echo $registration_url; ?>"><?php echo '<b class="home-display-button-text">' . $button_text . '</b>'?></a><?php ;
							}

Could you tell me if I’m on the right track here?


Tony

  • Support Staff

November 3, 2016 at 8:42 pm

Hi there,

Which template are you editing and which version of Event Espresso are you currently using?

The code above looks like it would be for EE3 so I just want to confirm first.


dlamunyon

November 4, 2016 at 8:33 pm

We are using EE4 and the espresso-grid-template.


Tony

  • Support Staff

November 7, 2016 at 6:17 pm

Ok, then no, you are not on the right track as the above code is aimed at EE3 not EE4.

With EE4 the price is assigned to a ticket and then the ticket (or multiple tickets) are assigned to a ‘datetime’.

You would need to pull the tickets for the current datetime shown in the grid, loop over them and check that none of them have a cost associated with them and then change the text output to the screen, there is no such $event->event_cost parameter/method that will return a single value you can use within EE4.

You can use the EE4 Model system to pull all of the information you need, take a look here:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

Also take a look at this tutorial:

https://gist.github.com/lorenzocaum/ef6afefd07c9c5f6f681

Note that it does NOT apply to the grid template, but will give you more of idea to of how to get the information you need.

Viewing 3 reply threads

The support post ‘Change Button Text If Event Is Free’ 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