Support

Home Forums Event Espresso Premium Free workshops show prices in the pricing table

Free workshops show prices in the pricing table

Posted: June 4, 2019 at 8:00 am


Oguzhan Altun

June 4, 2019 at 8:00 am

Follow up to this support ticket with Tony:
https://eventespresso.com/topic/member-prices-for-some-events-in-the-pricing-table/

We have a problem that I didn’t recognize in the previous support ticket. What we call the “member workshops” with free tickets only available for members: They show a price in the pricing table, even if they are free entrance. Here you can see:

https://www.genevaphotoclub.com/dates-prices/
See the events on 7, 8, 14 june, they all show a price of 190chf, but in fact they are free for members (you can see by clicking Book Now).

I think it shows the previous event’s price instead of free.

Could you let me know how to solve this?


Josh

  • Support Staff

June 4, 2019 at 8:23 am

Hi,

It looks like the way your custom code is pulling the prices, it’s setting a variable somewhere, so that June 4 class price at 190.00 is getting through to the next loop. In other words, you need to initialize your price variable so it always starts as 0 or an empty string.

Looking at the gist from your other topic, what you could do is right after this line:
//check if the ticket is free, if set the ticket price to 'Free'
add this:
$ticket_price = 0;
add that just before:
if ( $ticket instanceof EE_Ticket ) {


Oguzhan Altun

June 4, 2019 at 9:37 am

Hi Josh,

I added the code but the issue persists:
https://zurich.swissphotoclub.com/en/dates-prices/

Here is the latest status with your code:

https://gist.github.com/altuno/394a15ad09009d55407baab884438e7a


Josh

  • Support Staff

June 4, 2019 at 9:58 am

Oh okay, yeah I see further up above there’s some logic that doesn’t check for the tickets if the event is sold out. So the tickets from one event can end up being used for other events. What you’ll need to do is go through and initialize any variables that need to be unique for each event, when there’s any chance that they might not get set due to logic.

So for example, to fix the above problem where you have this:

if ( ! $event->is_sold_out() ) {

            // grab array of EE_Ticket objects for event
$tickets = EEH_Event_View::event_tickets_available( $post->ID );

You’ll need to either remove that sold out check, or initialize the $tickets variable, or add an else statement that also gets the tickets, then does something else. The entire template could use some cleaning up and a code review because there could be some other gotchas in there.


Oguzhan Altun

June 4, 2019 at 10:04 am

Thank you Josh.

I don’t know how to code at all. Would you be kind enough to tell me what to replace this code with, to fix this problem?

Indeed, the template code is now quite messy and needs reviewing. We will have the budget to hire a developer for this in a few months.


Josh

  • Support Staff

June 4, 2019 at 11:05 am

I’m not 100% sure how to fix this as it’s not my code or code I normally support, and the code has a lot of extra things that don’t make sense to me. So I hope you can understand this isn’t a case of not being kind enough to help, it’s a case of not knowing exactly how to fix someone else’s code. So you may need to do some trial and error with this.

If I were going to troubleshoot this, I’d start with moving the if statement after that sold out check so the $tickets object gets set even if the event is sold out. In other words, move this:
if ( ! $event->is_sold_out() ) {
to the line after this:
$tickets = EEH_Event_View::event_tickets_available( $post->ID );

Again, I don’t know if that’s going to fix the issue. There’s over a 1000 lines of code in that template and it probably has other gotchas that aren’t in the templates we provide and support.


Oguzhan Altun

June 4, 2019 at 11:21 am

Hi Josh,

Sure, I fully understand your pov, certainly not asking you to go through 1000 lines of code:)

I tried but it didn’t fix the issue.

What might help is that there was no problem with free courses before the changes we did with Tony from the previous ticket. So this issue cropped up after the changes we did with him from that thread.

Does that help to narrow the issue?


Josh

  • Support Staff

June 4, 2019 at 11:47 am

So if you undo the changes that Tony advised does that fix the issue?


Oguzhan Altun

June 4, 2019 at 12:00 pm

Exactly, but then we have the problem he solved – about members only prices showing for some events in the table


Josh

  • Support Staff

June 4, 2019 at 12:43 pm

He didn’t exactly solve the problem, he pointed you in the direction of a solution and the solution wasn’t followed through fully. The solution is really something that a developer really needs to do, because again, we do not support adding prices to this template. Adding pricing there adds so much complexity to an otherwise simple template.

So that said, back to the issue where you have variables that are not initialized. On line 358, you have a $cap_required variable being set, but it’s not initialized. You’ll need to initialize that variable so the next ticket to get looped through doesn’t get the same variable because the other ticket doesn’t have a required ticket cap.


Oguzhan Altun

June 5, 2019 at 4:13 am

Thank you Josh. So how do I fix that in the code?
Also, is there anything I should do differently while creating the members free ticket to prevent the issue or make the code update easier?


Tony

  • Support Staff

June 6, 2019 at 10:33 am

The problem is that in your other post you requested we only use a ticket that has no capability set on it, but with these events, it seems there are only member tickets (or a single member ticket) all with a capability set on them (it), right?

You can’t set up those events different with the way the code is now as it expects at least 1 ticket not to have a capability.

So there’s a couple of steps to fixing this.

First, add:

// initialize $ticket
$ticket = null;

You can add that just after this line: https://gist.github.com/altuno/394a15ad09009d55407baab884438e7a#file-template-oa-L354

Then just after the code I gave you previously, add this:

// If at this point we have tickets, but a single ticket has not been found then all of the tickets on the event have a capability,
// so let's pull the first ticket we have and use that.
if(is_null($ticket) && !empty($tickets)) {
    $ticket = reset($tickets);
}

Which is basically saying if the code I gave you earlier didn’t find a ticket, go back to pulling the first ticket from $tickets again. So it looks a little something like this:

// grab array of EE_Ticket objects for event
$tickets = EEH_Event_View::event_tickets_available( $post->ID );
// initialize $ticket
$ticket = null;

//Loop through all of the available tickets and set $ticket to the first ticket found without a capability
foreach($tickets as $temp_ticket) {
    if($temp_ticket instanceof EE_Ticket) {
        // Pull the capability set on the ticket
        $cap_required = $temp_ticket->get_extra_meta('ee_ticket_cap_required', true);
        // We want a ticket with no cap set
        if(!$cap_required) {
            $ticket = $temp_ticket;
            break;
        }
    }
}

// If at this point we have tickets, but a single ticket has not been found then all of the tickets on the event have a capability,
// so lets pull the first ticket we have and use that.
if(is_null($ticket) && !empty($tickets)) {
    $ticket = reset($tickets);
}

As Josh mentioned, the code in that template is getting rather cluttered and could do with a refactor, there are a fair few unnessacary steps going on in that template now.


Oguzhan Altun

June 8, 2019 at 8:33 am

Hello Tony,

Thank you so much, the issue seems to be fixed now.

There is an odd error (the intensive course on June 16th is full but shows price of zero instead of sold-out), but the big issue is solved.

Thank you so much both for your help and flexibility on this.


Oguzhan Altun

June 8, 2019 at 8:33 am

https://www.genevaphotoclub.com/dates-prices/


Oguzhan Altun

June 8, 2019 at 8:34 am

the intensive course here: https://www.genevaphotoclub.com/dates-prices/


Tony

  • Support Staff

June 10, 2019 at 6:43 am

The reason that is happening is the event status is not sold out, so this check:

if ( ! $event->is_sold_out() ) {

Is returning that the event is not sold out and it’s running through all of the ticket set up.

I know that is happening because of the banner on the event page – https://monosnap.com/file/MS6QWmnI5ExrGXxNT0Ovr8hZO1ijeC

Example of a sold out event – https://monosnap.com/file/HmxahqR3KodFo4RkAHsSeFFIxm3XPk

That info is also available in a couple of other locations, but the point being the event does not have a status of sold out, the ticket current does, but not the event, so the code is working as expected.


Oguzhan Altun

June 10, 2019 at 10:14 am

Hi Tony,

This is indeed the case! Any idea why that upcoming event is not automatically changing status to sold-out?

Here is the screenshot from event admin:
https://monosnap.com/file/EnT1NSYIIa5sHCeaCMsk340pb9WjWo
https://monosnap.com/file/rmhWZLP7vxu8r6mIApp926UUP2ZWIt

All tickets are sold, event capacity 8 people, 8 approved registrations.

PS: let me know if you’d like me to create a new topic, as this one is solved for the purpose it was created.


Tony

  • Support Staff

June 13, 2019 at 4:03 pm

I did some digging into this and it looks like its a bug caused by the archived ticket not being included in the sold out check.

I’ve created a ticket to investigate this further, for the time being, you will need to manually set that event to sold out in order for it to show as such.


Oguzhan Altun

June 18, 2019 at 9:40 am

OK great, thanks for looking into this. Would be great if let me know when this bug is resolved, so that I can tell my team that they don’t have to do this manually. I will check in the release notes as well.


Josh

  • Support Staff

June 18, 2019 at 9:47 am

The fix in EE4 core was included in the very latest release (v. 4.9.82.p)

The support post ‘Free workshops show prices in the pricing table’ 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