Skip Navigation

[Resolved] Refresh view

This thread is resolved. Here is a description of the problem and solution.

Problem: If no items are found in a View of WooCommerce Orders, I would like to automatically refresh the View results after a set amount of time.

Solution: There is no automatic feature for refreshing View results, nor is there a true JavaScript API for Views, but you could achieve something similar by reloading the current page in a setTimeout function added to a script tag in the wpv-no-items-found block of the View, for example:

[wpv-no-items-found]
    <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    <script type="text/javascript">setTimeout(function(){location.reload();}, 5000);</script>
[/wpv-no-items-found]

This will reload the current page after 5 seconds if no results are found in the View. That loop of refreshing every 5 seconds would continue until results exist.

Relevant Documentation:
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Timeouts_and_intervals

This support ticket is created 2 years, 9 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Puntorosso 2 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#2117141

Hi,
I have a View showing all WooCommerce orders still in "Processing" status.
Every item has a Cred submit button that set the order to complete.

Our staff press the button when the order has been processed, and the order disappear from the list.
This action refresh also the View, so we see also the new orders coming in.

The problem is only when the list is empty, as the staff won't press any submit button and the View won't refresh.
Is it possible to auto-refresh the View when "idle"?

Thanks

#2118191

Hello, there is no automatic refresh option built-in to Views, but you could use a custom JavaScript snippet in the "no results found" section to reload the page with a short timeout when there are no results found in the View. If you created the View in the legacy editor, you could do something like this in the Loop Editor:

	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
		<script type="text/javascript">setTimeout(function(){location.reload();}, 5000);</script>
	[/wpv-no-items-found]

In this case, if the View produces "no results found", a 5-second (5000 milliseconds) timer will begin. After 5 seconds, the page will reload automatically. You can change 5000 to adjust the timer.
https://developer.mozilla.org/en-US/docs/Web/API/Location/reload

#2118193

That's a simple but great idea!

Thanks a lot Christian.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.