Following the instructions given in a previous discussion, I’m trying to find the end date of the sale period for a ticket using eo_get_event_tickets().
A var_dump of $ticket gives…
array(1) {
[719890]=> object(EO_Event_Ticket_Type)#7351 (4) {
["price":"EO_Event_Ticket_Type":private]=> object(EO_Money)#7358 (2) {
["amount_in_fractional_unit":"EO_Money":private]=> float(1320)
["currency":"EO_Money":private]=> object(EO_Currency)#7352 (4) {
["name":"EO_Currency":private]=> string(20) "GBP - British Pounds"
["symbol":"EO_Currency":private]=> string(2) "£"
["fractional_units_in_standard":"EO_Currency":private]=> int(100)
["iso_code"]=> string(3) "GBP"
}
}
["mid"]=> int(719890)
["period"]=> object(EO_Date_Range)#7356 (2) {
["from":"EO_Date_Range":private]=> NULL
["until":"EO_Date_Range":private]=> object(DateTime)#7357 (3) {
["date"]=> string(26) "2021-07-31 23:59:00.000000"
["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/London"
}
}
["storage":"ArrayObject":private]=> array(8) {
["mid"]=> int(719890)
["name"]=> string(14) "Hannah Peschar"
["spaces"]=> int(30)
["price"]=> float(13.2)
["order"]=> int(0)
["from"]=> bool(false)
["to"]=> object(DateTime)#7357 (3) {
["date"]=> string(26) "2021-07-31 23:59:00.000000"
["timezone_type"]=> int(3)
["timezone"]=> string(13) "Europe/London"
}
["occurrence_ids"]=> array(1) {
[0]=> int(1507)
}
}
}
}
… but $ticket[‘to’] comes up empty, and so does $ticket[‘name’].
Here’s the code I’m using:
$occurrences = eo_get_the_occurrences_of();
if ( count($occurrences) === 1 ) {
$ticket = eo_get_event_tickets( get_the_ID(), (int) eo_get_the_occurrence_id() );
// echo var_dump($ticket);
echo 'ticket-name = "'.$ticket['name'].'"';
echo 'ticket-to = "'.$ticket['to'].'"';
}
I’ve also tried $ticket[‘storage’][‘name’] but can’t get any result. Please, where am I going wrong?
Michael Docker
There is a function $ticket->on_sale_until()
which will return null
or DateTime
object.
So the following should work:
$sale_end = $ticket->on_sale_until();
if ($sale_end) {
echo $sale_end->format('jS F Y');
}
Stephen Harris
Thanks Stephen.
When I use your $sale_end code I get the following:
“Error thrown
Call to a member function on_sale_until() on array”
A similar error message greets the is_currently_on_sale( ) function
I am using a new ‘test event’ with sale dates between 15 Aug 2021 and 21 Jun 2022
Michael Docker
Hi Michael,
What version are you running? eo_get_event_tickets()
should return an array of EO_Event_Ticket_Type
, not an array of arrays.
Stephen Harris
I’m using EO v3.10.7 and Pro v3.2.0.
I get an array of arrays, as above, with the following code:
$ticket = eo_get_event_tickets();
echo var_dump($ticket);
Michael Docker
Ah, ok. I’ve just realised what’s happening. In your code above $ticket is not a single ticket, its an array of the events tickets. Either you can iterate over it or if you’re expecting only one you can ‘pop’ it.
$tickets = eo_get_event_tickets();
$ticket = array_pop($tickets);
$sale_end = $ticket->on_sale_until();
if ($sale_end) {
echo $sale_end->format('jS F Y');
}
Stephen Harris
Thanks Stephen, that’s cracked it. Just the ticket!
Michael Docker