Can't get sale-end datetime

This topic contains 6 replies, has 2 voices, and was last updated by  Michael Docker 1 month, 4 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #40099

    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
    #40116

    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
    #40128

    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
    #40350

    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
    #40365

    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
    #40369

    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
    #40383

    Thanks Stephen, that’s cracked it. Just the ticket!

    Michael Docker
Viewing 7 posts - 1 through 7 (of 7 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.