tribe_events_has_tickets_on_sale returns 0 during last sold day

Home Forums Ticket Products Event Tickets Plus tribe_events_has_tickets_on_sale returns 0 during last sold day

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1425452
    valerio
    Participant

    Hi All,
    I’m using the function tribe_events_has_tickets_on_sale($post_id) inside a custom divi display module for a conditional formatting when a specific event has ticket availables.
    It worked very well untill last major update… After the update the boolean returned in 0 for events that are sold on current day.
    I think the problem is date comparision as if the date doesn’t include the time.
    For exaple if I want to sell an event from today 10:30 am till tomorrow 10:30 the boolean will be 1 till today 11:59pm. After that the boolean it’s gonna be 0.
    Instead, on the event page ticket are correctly shown following date time interval…
    Any idea about the reason?
    Any hack I can do on the plugins\event-tickets\src\template-tags\tickets.php?
    Thanks!
    V.

    #1426467
    valerio
    Participant

    Friendly bumb… sorry… 😉

    #1426748

    Hi Valerio,

    Thanks so much for reaching out!

    Just to let you know, we are limited by our Support Policy in how much we can help with customizations, but I will try to point you in the right direction.

    Our Themer’s Guide is a great place to start, which can show you how to copy and edit our templates, although it sounds like you have already begun your investigation there.

    If this functionality is a requirement for your intended project, I’d suggest that a third-party developer would be the best way to make this feature happen on a short timeline. ? We maintain a list of developers who work with our plugins on our Knowledgebase here:

    https://theeventscalendar.com/knowledgebase/find-a-customizer/

    Please let me know if you have any other questions on this topic!

     

    Thanks,

    Jaime

    #1426941
    valerio
    Participant

    Hi Jamie,
    I don’t want to customize anything: my project is online and it works from last summer… so I’m not talking about a beta project.
    I’m just wondering why a non-custimized fuction such as tribe_events_has_tickets_on_sale stopped to work since last plugin update.
    In fact my site was working very well until last Events Ticket release.
    I’m using tribe_events_has_tickets_on_sale on my template for a simple conditional formatting (icons thumbs and a specific style for events that are actually for sale) and I didn’t hack anything in the event tickets core.

    My event:
    1. Is avilable (1 or more places available)
    2. Can be sold (today is between the two dates picked in the ticket options)
    But… the function returns 1 (true) till the last day… then it gives me 0 (false).

    For example:
    MYevent
    Availability: 10 places
    start sell: 01/01/2018 h21:00
    end sell: 15/01/2018 h20:00
    The function returns 1 as expected until 14/01/2018 @23:59, then on 15/01/2018 00:00 it returns 0.
    Any idea about that?

    Thanks.
    Valerio

    #1427699

    Hi Valerio,

    Thanks for your explanation.  Can you check if your function works on a default WordPress theme, like ‘Twentyseventeen’?

    I just want to ensure that there isn’t a theme conflict there.

    Let me know!

     

    Thanks,

    Jaime

    #1430265
    valerio
    Participant

    Is there any developer out there?
    I do not wish to be controversial.. but helpdesk should be able to understand this kind of problems at first glance.
    Just control how the function is built…
    I didn’t check in which part of the plugin the tribe_events_has_tickets_on_sale returns is used.
    So I don’t now why it calculates the onSale status just using the day.
    It could be a problem for a lastminute ticket platform where time is crucial.
    If you look at the original MT code in
    wp-content\plugins\event-tickets\src\template-tags\tickets.php
    @ bout line 340 you’ll find start and end calculated without time:

        $now    = current_time( 'timestamp' );
        $start  = strtotime( $ticket->start_date );
        $finish = strtotime( $ticket->end_date );
    

    It means that $start and $finish variables are just the day of start and finish, without time.
    The boolean is calculated here:

        $has_started = ( empty( $ticket->start_date ) || ( $start && $now > $start ) );
        $not_ended   = ( empty( $ticket->end_date ) || ( $finish && $now start_date ) && empty( $ticket->end_date ) ) {
            return true;
        }
    
        // Timestamps for comparison purposes: added time to be more accurate than the original MT function
        $timestart = $ticket->start_time;
        $timefinish = $ticket->end_time;
        $daystart = $ticket->start_date;
        $dayfinish = $ticket->end_date;
    
        $startdt = $daystart . ' ' . $timestart;
        $finishdt = $dayfinish . ' ' . $timefinish;
    
        $now    = current_time( 'timestamp' );
        $start  = strtotime( $startdt );
        $finish = strtotime( $finishdt );
    
    
        // Are we within the applicable date range?
        $has_started = ( empty( $ticket->start_date ) || ( $start && $now > $start ) );
        $not_ended   = ( empty( $ticket->end_date ) || ( $finish && $now < $finish ) );
    
        //what a mess? Don't worry: here you are all those pretty variables if you want to control vars content
        //echo $startdt;
        //echo $finishdt;
        //echo &quot;inizio=&quot; . $start . &quot;<br>";
        //echo "fine=" . $finish . "<br>";
        //echo "adesso=" . $now . "<br>";
    
        // Result
        return ( $has_started &amp;&amp; $not_ended );
    }
    

    }//end if

    if ( ! function_exists( ‘tickit_events_has_tickets_on_sale’ ) ) {
    /**
    * Checks if the event has any tickets on sale
    *
    * @param int $event_id
    *
    * @return bool
    */
    function tickit_events_has_tickets_on_sale( $event_id ) {
    $has_tickets_on_sale = false;
    $tickets = Tribe__Tickets__Tickets::get_all_event_tickets( $event_id );
    foreach ( $tickets as $ticket ) {
    $has_tickets_on_sale = ( $has_tickets_on_sale || tickit_events_ticket_is_on_sale( $ticket ) );
    }

        return $has_tickets_on_sale;
    }
    

    }

    Hope to be useful for those who wants to use the onsale function on their template for a more accurate calculation.
    Maybe the original function is correct… As I said I didn’t check in which part of the plugin is used.
    BYE
    V.

    • This reply was modified 6 years, 3 months ago by valerio.
    • This reply was modified 6 years, 3 months ago by valerio.
    • This reply was modified 6 years, 3 months ago by Leah.
    #1430268
    valerio
    Participant

    Is there any developer out there?
    I do not wish to be controversial.. but helpdesk should be able to understand this kind of problems at first glance.
    Just control how the function is built…
    I didn’t check in which part of the plugin the tribe_events_has_tickets_on_sale returns is used.
    So I don’t now why it calculates the onSale status just using the day.
    It could be a problem for a lastminute ticket platform where time is crucial.
    If you look at the original MT code in
    wp-content\plugins\event-tickets\src\template-tags\tickets.php
    @ bout line 340 you’ll find start and end calculated without time:

        $now    = current_time( 'timestamp' );
        $start  = strtotime( $ticket-&gt;start_date );
        $finish = strtotime( $ticket-&gt;end_date );
    

    It means that $start and $finish variables are just the day of start and finish, without time.
    The boolean is calculated here:

        $has_started = ( empty( $ticket-&gt;start_date ) || ( $start &amp;&amp; $now &gt; $start ) );
        $not_ended   = ( empty( $ticket-&gt;end_date ) || ( $finish &amp;&amp; $now start_date ) &amp;&amp; empty( $ticket-&gt;end_date ) ) {
            return true;
        }
    
        // Timestamps for comparison purposes: added time to be more accurate than the original MT function
        $timestart = $ticket-&gt;start_time;
        $timefinish = $ticket-&gt;end_time;
        $daystart = $ticket-&gt;start_date;
        $dayfinish = $ticket-&gt;end_date;
    
        $startdt = $daystart . ' ' . $timestart;
        $finishdt = $dayfinish . ' ' . $timefinish;
    
        $now    = current_time( 'timestamp' );
        $start  = strtotime( $startdt );
        $finish = strtotime( $finishdt );
    
    
        // Are we within the applicable date range?
        $has_started = ( empty( $ticket-&gt;start_date ) || ( $start &amp;&amp; $now &gt; $start ) );
        $not_ended   = ( empty( $ticket-&gt;end_date ) || ( $finish &amp;&amp; $now &lt; $finish ) );
    
        //what a mess? Don't worry: here you are all those pretty variables if you want to control vars content
        //echo $startdt;
        //echo $finishdt;
        //echo &quot;inizio=&quot; . $start . &quot;<br>";
        //echo "fine=" . $finish . "<br>";
        //echo "adesso=" . $now . "<br>";
    
        // Result
        return ( $has_started &amp;&amp; $not_ended );
    }
    

    }//end if

    if ( ! function_exists( ‘tickit_events_has_tickets_on_sale’ ) ) {
    /**
    * Checks if the event has any tickets on sale
    *
    * @param int $event_id
    *
    * @return bool
    */
    function tickit_events_has_tickets_on_sale( $event_id ) {
    $has_tickets_on_sale = false;
    $tickets = Tribe__Tickets__Tickets::get_all_event_tickets( $event_id );
    foreach ( $tickets as $ticket ) {
    $has_tickets_on_sale = ( $has_tickets_on_sale || tickit_events_ticket_is_on_sale( $ticket ) );
    }

        return $has_tickets_on_sale;
    }
    

    }

    Hope to be useful for those who wants to use the onsale function on their template for a more accurate calculation.
    Maybe the original function is correct… As I said I didn’t check in which part of the plugin is used.
    BYE
    V.

    • This reply was modified 6 years, 3 months ago by valerio.
    • This reply was modified 6 years, 3 months ago by Leah.
    #1430271
    valerio
    Participant

    Is there any developer out there?
    I do not wish to be controversial.. but helpdesk should be able to understand this kind of problems at first glance.
    Just control how the function is built…
    I didn’t check in which part of the plugin the tribe_events_has_tickets_on_sale returns is used.
    So I don’t now why it calculates the onSale status just using the day.
    It could be a problem for a lastminute ticket platform where time is crucial.
    If you look at the original MT code in
    wp-content\plugins\event-tickets\src\template-tags\tickets.php
    @ bout line 340 you’ll find start and end calculated without time:

        $now    = current_time( 'timestamp' );
        $start  = strtotime( $ticket-&gt;start_date );
        $finish = strtotime( $ticket-&gt;end_date );
    

    It means that $start and $finish variables are just the day of start and finish, without time.
    The boolean is calculated here:

        $has_started = ( empty( $ticket-&gt;start_date ) || ( $start &amp;&amp; $now &gt; $start ) );
        $not_ended   = ( empty( $ticket-&gt;end_date ) || ( $finish &amp;&amp; $now start_date ) &amp;&amp; empty( $ticket-&gt;end_date ) ) {
            return true;
        }
    
        // Timestamps for comparison purposes: added time to be more accurate than the original MT function
        $timestart = $ticket-&gt;start_time;
        $timefinish = $ticket-&gt;end_time;
        $daystart = $ticket-&gt;start_date;
        $dayfinish = $ticket-&gt;end_date;
    
        $startdt = $daystart . ' ' . $timestart;
        $finishdt = $dayfinish . ' ' . $timefinish;
    
        $now    = current_time( 'timestamp' );
        $start  = strtotime( $startdt );
        $finish = strtotime( $finishdt );
    
    
        // Are we within the applicable date range?
        $has_started = ( empty( $ticket-&gt;start_date ) || ( $start &amp;&amp; $now &gt; $start ) );
        $not_ended   = ( empty( $ticket-&gt;end_date ) || ( $finish &amp;&amp; $now &lt; $finish ) );
    
        //what a mess? Don't worry: here you are all those pretty variables if you want to control vars content
        //echo $startdt;
        //echo $finishdt;
        //echo &quot;inizio=&quot; . $start . &quot;<br>";
        //echo "fine=" . $finish . "<br>";
        //echo "adesso=" . $now . "<br>";
    
        // Result
        return ( $has_started &amp;&amp; $not_ended );
    }
    

    }//end if

    if ( ! function_exists( ‘tickit_events_has_tickets_on_sale’ ) ) {
    /**
    * Checks if the event has any tickets on sale
    *
    * @param int $event_id
    *
    * @return bool
    */
    function tickit_events_has_tickets_on_sale( $event_id ) {
    $has_tickets_on_sale = false;
    $tickets = Tribe__Tickets__Tickets::get_all_event_tickets( $event_id );
    foreach ( $tickets as $ticket ) {
    $has_tickets_on_sale = ( $has_tickets_on_sale || tickit_events_ticket_is_on_sale( $ticket ) );
    }

        return $has_tickets_on_sale;
    }
    

    }

    Hope to be useful for those who wants to use the onsale function on their template for a more accurate calculation.
    Maybe the original function is correct… As I said I didn’t check in which part of the plugin is used.
    BYE
    V.

    #1430272
    valerio
    Participant

    Is there any developer out there?
    I do not wish to be controversial.. but helpdesk should be able to understand this kind of problems at first glance.
    Just control how the function is built…
    I didn’t check in which part of the plugin the tribe_events_has_tickets_on_sale returns is used.
    So I don’t now why it calculates the onSale status just using the day.
    It could be a problem for a lastminute ticket platform where time is crucial.
    If you look at the original MT code in
    wp-content\plugins\event-tickets\src\template-tags\tickets.php
    @ bout line 340 you’ll find start and end calculated without time:

        $now    = current_time( 'timestamp' );
        $start  = strtotime( $ticket-&gt;start_date );
        $finish = strtotime( $ticket-&gt;end_date );
    

    It means that $start and $finish variables are just the day of start and finish, without time.
    The boolean is calculated here:

        $has_started = ( empty( $ticket-&gt;start_date ) || ( $start &amp;&amp; $now &gt; $start ) );
        $not_ended   = ( empty( $ticket-&gt;end_date ) || ( $finish &amp;&amp; $now start_date ) &amp;&amp; empty( $ticket-&gt;end_date ) ) {
            return true;
        }
    
        // Timestamps for comparison purposes: added time to be more accurate than the original MT function
        $timestart = $ticket-&gt;start_time;
        $timefinish = $ticket-&gt;end_time;
        $daystart = $ticket-&gt;start_date;
        $dayfinish = $ticket-&gt;end_date;
    
        $startdt = $daystart . ' ' . $timestart;
        $finishdt = $dayfinish . ' ' . $timefinish;
    
        $now    = current_time( 'timestamp' );
        $start  = strtotime( $startdt );
        $finish = strtotime( $finishdt );
    
    
        // Are we within the applicable date range?
        $has_started = ( empty( $ticket-&gt;start_date ) || ( $start &amp;&amp; $now &gt; $start ) );
        $not_ended   = ( empty( $ticket-&gt;end_date ) || ( $finish &amp;&amp; $now &lt; $finish ) );
    
        //what a mess? Don't worry: here you are all those pretty variables if you want to control vars content
        //echo $startdt;
        //echo $finishdt;
        //echo &quot;inizio=&quot; . $start . &quot;<br>";
        //echo "fine=" . $finish . "<br>";
        //echo "adesso=" . $now . "<br>";
    
        // Result
        return ( $has_started &amp;&amp; $not_ended );
    }
    

    }//end if

    if ( ! function_exists( ‘tickit_events_has_tickets_on_sale’ ) ) {
    /**
    * Checks if the event has any tickets on sale
    *
    * @param int $event_id
    *
    * @return bool
    */
    function tickit_events_has_tickets_on_sale( $event_id ) {
    $has_tickets_on_sale = false;
    $tickets = Tribe__Tickets__Tickets::get_all_event_tickets( $event_id );
    foreach ( $tickets as $ticket ) {
    $has_tickets_on_sale = ( $has_tickets_on_sale || tickit_events_ticket_is_on_sale( $ticket ) );
    }

        return $has_tickets_on_sale;
    }
    

    }

    Hope to be useful for those who wants to use the onsale function on their template for a more accurate calculation.
    Maybe the original function is correct… As I said I didn’t check in which part of the plugin is used.
    BYE
    V.

    #1430276
    valerio
    Participant

    Sorry…
    I cannot correctly paste my solution.
    The file is attached.

    #1430343

    Hi Valerio,

    Glad you were able to resolve your issue, and thanks for sharing your solution, you are welcome back in our support forums any time!

    Since you marked this thread as Resolved, I am going to close this thread.

    Have a great weekend!

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘tribe_events_has_tickets_on_sale returns 0 during last sold day’ is closed to new replies.