Home › Forums › Ticket Products › Event Tickets Plus › tribe_events_has_tickets_on_sale returns 0 during last sold day
- This topic has 11 replies, 3 voices, and was last updated 6 years, 3 months ago by valerio.
-
AuthorPosts
-
January 13, 2018 at 4:05 am #1425452valerioParticipant
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.January 15, 2018 at 6:15 am #1426467valerioParticipantFriendly bumb… sorry… 😉
January 15, 2018 at 11:31 am #1426748Jaime MarchwinskiKeymasterHi 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
January 15, 2018 at 2:26 pm #1426941valerioParticipantHi 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.
ValerioJanuary 16, 2018 at 9:19 am #1427699Jaime MarchwinskiKeymasterHi 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
January 19, 2018 at 1:31 am #1430265valerioParticipantIs 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 "inizio=" . $start . "<br>"; //echo "fine=" . $finish . "<br>"; //echo "adesso=" . $now . "<br>"; // Result return ( $has_started && $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.January 19, 2018 at 1:36 am #1430268valerioParticipantIs 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 "inizio=" . $start . "<br>"; //echo "fine=" . $finish . "<br>"; //echo "adesso=" . $now . "<br>"; // Result return ( $has_started && $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.January 19, 2018 at 1:38 am #1430271valerioParticipantIs 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 "inizio=" . $start . "<br>"; //echo "fine=" . $finish . "<br>"; //echo "adesso=" . $now . "<br>"; // Result return ( $has_started && $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.January 19, 2018 at 1:38 am #1430272valerioParticipantIs 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 "inizio=" . $start . "<br>"; //echo "fine=" . $finish . "<br>"; //echo "adesso=" . $now . "<br>"; // Result return ( $has_started && $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.January 19, 2018 at 1:40 am #1430276valerioParticipantSorry…
I cannot correctly paste my solution.
The file is attached.January 19, 2018 at 3:22 am #1430343Jaime MarchwinskiKeymasterHi 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!
-
AuthorPosts
- The topic ‘tribe_events_has_tickets_on_sale returns 0 during last sold day’ is closed to new replies.