vendredi 29 mars 2019

Issues with multiple elseif statements

Trying to create a lengthy series of if else statements. Basically, four different scenarios to bring up different button based on queries.

If the event is free, have a button saying so.

However, if the event is free, but you have to RSVP (like our meetups), show this button

Or if there are tickets but the event isn’t free but has a discount, show this button,

Else if there are tickets but they aren’t free, show this button.

And this is what I currently have.

if ( isset($additional_fields[ 'Price' ]) == 'Free' ) {
    echo '<button class="btn-free">This Event is Free!</button></a>';
} elseif( isset($additional_fields[ 'Tickets' ]) && (isset($additional_fields[ 'Price' ])) == 'Free' ) {
    echo '<a href="' . $additional_fields[ 'Tickets' ] . '" target="_blank"><button class="btn-rsvp">Free with RSVP</button></a>';
} elseif( isset($additional_fields[ 'Tickets' ]) && (isset($additional_fields[ 'Price' ])) != 'Free' && (isset($additional_fields[ 'Discounts' ]))) {
    echo '<a href="' . $additional_fields[ 'Tickets' ] . '" target="_blank"><button class="btn-discount">Tickets ' . $additional_fields[ 'Discount Text' ] . '</button></a>';
} elseif( isset($additional_fields[ 'Tickets' ]) ){
    echo '<a href="' . $additional_fields[ 'Tickets' ] . '" target="_blank"><button class="btn-tkts">Get Tickets</button></a>';
}

Code works.... to a point. If I have an event that is free, I get the This Event is Free button, but if I have an event that is free but also offers tickets / rsvp, I still get the first free button with no link. The second step should be occurring here. Not the first. Same deal if add a price or anything beyond the word 'Free'.

Is my order correct? Or something else in the code?

Aucun commentaire:

Enregistrer un commentaire