Skip Navigation

[Resolved] Button to search businesses that are Open Now and display Open Now text

This support ticket is created 3 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 23 replies, has 3 voices.

Last updated by Omek 3 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2104749

Thanks for writing back.

Like posts, Views that you create also have their IDs. You can visit WP Admin -> Toolset -> Views to see them.
( screenshot: hidden link )

The custom filtering code from my last message would only work for a view, if its ID is added in the line for the target views. For example:


$target_views = array(725, 646);

As a result, the custom filtering function will only work for views "TestView1" and "SearchView" and you can include or exclude the view IDs as needed.

Also enabling this open/close filtering on user requests will be tricky since it is not possible to include a custom input field in the view's search form. One workaround can be to to create two separate search pages with separate views. One can be for the search for all the businesses and the other can be only for the open now businesses.

Unfortunately, the information that you shared about the failed tests is not enough for this troubleshooting.
(I requested very specific points in my last message)

I can understand that this ticket has been open for many days now, but it is also important to remember that we've been trying to achieve something that is not something available out-of-the-box in Toolset.

Although 1-1 customization assistance is beyond the scope of support that we can provide over the support forum ( ref: https://toolset.com/toolset-support-policy/ ), we do our best to guide in the right direction whenever possible.

I feel that this thread contains enough information for someone proficient with PHP and WordPress understanding to iron out any missing bits. To troubleshoot and resolve any missing cases in a more efficient and timely manner, I'll strongly recommend hiring a professional from our list of recommended contractors: https://toolset.com/contractors/

This will save you from back and forth messaging and time. As Saturday and Sunday are my off-days, it is very less likely that I'll be able to cycle back to this ticket before Monday.

I hope you'll understand.

#2107231

Updating the target view ID as well as the $open_close_val to match the return value in the custom open check id function has the exclude working now.

In regards to your request of specific points
1. As I stated on June 29th and June 30th:
It works in the earlier hours of the day and evening.
After 8pm all businesses changed to "Closed Now" regardless if the closing time was set to much later.

2. Here is the link to the screenshot I posted on July 1st of the timezone settings:
https://toolset.com/wp-content/uploads/2021/07/2103457-tmezone.jpg
Was this screenshot not sufficient?

3. It's all posts. The tests failed on all of them, they all change to "Closed Now" after 8pm.

I'm sorry but I don't understand. I was initially told by a Toolset Supporter that what I was asking for isn't possible, at that time I was still within my 30 Day Refund window and I could've requested a refund and moved on. So I find it rather misleading for another Toolset Supporter to offer help that extended out of my refund window, with an implementation that isn't working correctly, only to be told about the support policy two weeks later and to be told to pay for a contractor.

#2108405

Glad that the post exclusion function is working now.

I tried to be very open about the fact that something that you're planning is not available out-of-the-box, with the Toolset plugins.

Also when I shared the custom code solution for the open/close check, I specifically shared a note that these example snippets are only to help customers get started in the right direction so that they or their developers can adjust or customize it further as needed.
( ref: https://toolset.com/forums/topic/button-to-search-businesses-that-are-open-now-and-display-open-now-text/#post-2098801 )

In light of this, it is unfortunate if someone would think that we try to help only for as long as the refund window gets lapsed.

Thinking this through, I feel obligated to assist you in the troubleshooting of the code snippet that I provided you, so that it works expectedly at all times.

You're welcome to share FTP access details in reply to this message so that I can debug and investigate this on your server.
(I still don't see the same issue after 8 pm timings on my test website)

Note: Your next reply will be private.

#2111887

Thank you for sharing these details.

For more specific debugging, I've followed these steps:

1. I've added a debugging custom shortcode, in your website's snippet section named "Open Now Search debug".

2. In the view "TestView1", I've included some debugging information that is only visible to the logged-in users.
( it is inside a div with class "open-shop-debug" )

3. I'll recommend visiting the page as a logged-in user during the 8pm - 12am time window and share a complete screenshot of the page /providers/ where this view is used and the debug information should be visible.

This should help in narrowing down at which step the code is failing.

#2112949
Tuesday-1236am-open.jpg
Tuesday-1235am-closed.jpg
Tuesday-1201am.jpg
Monday-1123pm.jpg
image1.jpg

Actual time (device time) located in the bottom right corner of image. Screenshots were taken Monday late PM and Tuesday early AM. Late Monday PM the debug $day shows tuesday when it should display monday. When the day changes to Tuesday the debug $day remains tuesday. I dont understand the $current_time, $startdatetime, $enddatetime numbers

image1.jpg shows businesses "Closed Now" when they should still be open. The debug $day shows tuesday when it should display monday.(attached image1.jpg)

Monday at 11:23pm $day incorrectly displays tuesday instead of monday.(attached image Monday-1123pm.jpg)
38 minutes later at 12:01am Tuesday the $day remains tuesday which is correct as the day is now tuesday (attached image Tuesday-1201am.jpg)

ID 58(Nurse Johnson) set to open on Tuesday 12:36am. At 12:35am it displays Closed Now correctly (attached image Tuesday-1235am-open.jpg)
At 12:36am its displays Open Now correctly (attached image Tuesday-1236am-open.jpg)
ID 60(Dr Jackson) has nothing entered on monday or tuesday but still has $startdatetime and $enddatetime

#2114367

Thank you for sharing these screenshots and observations. They proved very useful.

The day difference was the result of the day showing based on the default GMT value and not the timezone set in the WordPress settings.

In the debugging code snippet, I've replaced:


$day = strtolower(date('l'));

With:


$day = strtolower(current_time('l'));

That difference should be fixed now.

The numerical values for the $current_time, $startdatetime, $enddatetime etc were showing in the UNIX timestamp format.
( hidden link )

I've added their human-friendly equivalent values in the brackets below them, so that they are easier to read.
( screenshot: hidden link )

For now, I've added the text line at the bottom of the debugging information which evaluates whether the provider is open or not. You can ignore the value coming from the older shortcode.
( screenshot: hidden link )

#2114943
before-midnight.jpg
after-midnight.jpg

Still now working.

Debug for $day, $field_value, $current_time, are displaying correctly after 8pm.

Debug for $startdatetime-format-u and $enddatetime-format-u are displaying the wrong date.
$startdatetime and $enddatetime display July 15, 2021 (the actual date/device date is July 14, 2021). See attached before-midnight.jpg

$startdatetime and $enddatetime remain this way after midnight which is then the correct date. See attached after-midnight.jpg

#2116079

Ok, I've restructured the code to offset the time based on the WordPress settings at a more basic level.

This seems to be working even in the time window between 8 pm - 12 am and I have updated this new approach in the actual shortcode snippet "Open Now Search", for the shortcode "custom_open_check" too:


add_shortcode('custom_open_check', 'custom_open_check_func');
function custom_open_check_func( $atts ) {

	global $post;

	$a = shortcode_atts( array(
		'id' => $post->ID
	), $atts );
	
	$day = strtolower(current_time('l'));

	$field_slug = $day.'-hours';
	
	$field_value = types_render_field( $field_slug, array( 'item' => $a['id'], 'output' => 'raw' ) );

	$field_value_arr = explode('-', $field_value); 
	
	$wp_timezone = wp_timezone_string();
	$dateTimeZoneWP = new DateTimeZone($wp_timezone);
	
	$current_time = new DateTime('now', $dateTimeZoneWP );
	$current_time_u = $current_time->format('U');

	$startdatetime = new DateTime($field_value_arr[0], $dateTimeZoneWP );
	$startdatetime_u = $startdatetime->format('U');
	
	$enddatetime = new DateTime($field_value_arr[1], $dateTimeZoneWP);
	$enddatetime_u = $enddatetime->format('U');

	if(($startdatetime_u <= $current_time_u) && ($current_time_u <= $enddatetime_u)) {
		return 'OPEN NOW';
	}
	else
	{
		return 'CLOSED NOW';
	}
	
}

Once you've completed the testing and it is working, you can remove the code snippet "Open Now Search debug".

#2119481

It's works after 8pm now. My issue is resolved. Thank you!