Custom Order Reset time
-
Would it be possible to have an Order Reset option for a custom time? I have a client who runs a lunch delivery only, they can only take in 100 orders a day so they would like to close orders for the coming day’s menu by 3pm if it doesn’t hit 100 orders and reopen for the next day’s orders, maybe at 7 to 8 pm that same day. If they are limited to the midnight reset, they may lose some peak time for ordering.
I also wanted to know if it’s possible for the plugin to notify if orders hit a 90% threshold or inform when orders are closed out. So far, I haven’t seen anything that fits the bill and from WooCommerce notifications itself, there’s no such function…
-
Hi @proexcell88,
Thank you for the suggestion, I’ve opened a ticket on the plugin’s GitHub repository to make sure it doesn’t get lost in the shuffle.
As far as notifications go, you might consider hooking into the “woocommerce_new_order” action. An (untested) example of how this might look:
/** * Send an email to the store owner when orders reach 90% of the interval limit. */ add_action( 'woocommerce_new_order', function () { $limiter = new \Nexcess\LimitOrders\OrderLimiter(); $limit = $limiter->get_limit(); $remaining = $limiter->get_remaining_orders(); $percentage = 1 - ( $remaining / $limit ); $transient = 'limit_orders_90_percent_notification_sent'; // We either haven't reached our threshold or a notification has already been sent. if ( $percentage < 0.9 || false !== get_transient( $transient ) ) { return; } $store = get_option( 'blogname' ); $body = sprintf( 'Your WooCommerce Store, %1$s, has received %2$d orders, which is %3$d% of the limit of %4$d set in Limit Orders for WooCommerce.', $store, $limit - $remaining, round( $percentage * 100 ), $limit ); // Send an email to the store owner. wp_mail( get_option( 'admin_email' ), sprintf( '%1$s has reached 90% of its order limit', $store ), $body ); // Set the transient to prevent this email from being sent again for this interval. set_transient( $transient, time(), $limiter->get_seconds_until_next_interval() ); } );
Thanks Steve,
Will have to look into this as we’re not developers. It will be great if it gets implemented, both a 90% notification or a hit the order limit notification to remind shop owners to process orders and that the limit has been reached for the day.Is there a way to set the custom daily reset time as another function (similar to the 30 minute interval script we have seen)?
I did some digging and it seems that it’s actually pretty easy to pull off custom interval start times with the filters already available in the plugin.
I’ve put together a sample that you can use (after testing it out, of course) to customize the start time for the daily interval; all you’ll need to do is customize the
$hours
,$minutes
, and$seconds
variables to suit your client’s needs.Please remember that the hours in the script are based on 24-hour time (e.g. 8:00pm is 20:00)
Hi Steve – i too am interested in setting a customized time to reset orders of 7am.
I am not a developer and use the code snippets plug-in for php codes. Can i just paste the code you link to above into code snippets? and change the $variables
Thanks!
Fred
@vitalseeds Indeed, it should work just fine with Code Snippets.
Enjoy!
Great thanks Steve, just did it and seems to have worked.
And thanks for making the plug-in, its exactly what we need at the moment.
Awesome, glad to hear it!
Hi again Steve
in the end the filter did not seem to work properly. Ill explain exactly what happened and maybe you can advise.
-I installed the plug-in on sunday evening after too many orders had been received that day – i set the limit to 50
– orders were then disabled until midnight when the counter reset
– at around 12pm on monday the 50 order limit was reached and orders disabled
– i then added your code snippet to move order reset time to 7am and changed the values to as follows:
*/
$hours = 07;
$minutes = 0;
$seconds = 0;
– there was a message from the plug-in saying that orders were suspended until 7am, so i thought it was working
– BUT, then it seems the checkout opened again at midnight as we had some orders some in over the night
– at 7am the checkout was CLOSED (instead of opened again) and people were writing to complain that they could not order from us
– i then deactivated pluginDo you have any idea what is happening here?
Fred
@vitalseeds There are a few factors that could be in-play here:
1. Please ensure that your store’s timezone is set correctly within WP Admin (Settings > General > Timezone), as times are calculated based on the configured value.
2. Additionally, please make sure you’re running the latest version of Limit Orders (1.3.1) and that the snippet within Code Snippets.Checkout re-opening at midnight may have been the result of the “limit_orders_order_count” transient having been set, as changing the time via filter wouldn’t affect the transient if it already existed.
There are a few ways to clear that transient:
1. Via WP-CLI:
wp transient delete limit_orders_order_count
2. Delete the transient using a plugin like Transients Manager
3. Make and save any changes to the Limit Orders configuration (you can then change them right back)Your host may also offer a “Delete all transients” option, but this should be your last resort, as this will cause *all* transients to be cleared. They’re meant to be temporary (it’s essentially just flushing the cache), but it could result in some slowdowns as the caches are rebuilt.
HI thanks for that
I downloaded the plug-in but cant delete the ‘limit_orders_order_count’ transient, it just keeps returning when i click delete. It does say that it has ‘expired’ though.
update – i deleted the plug-in and tried to start from the beginning again. It seems that when i delete the active transient (50) a new transient (97) which is expired immediately appears in the transient list in its place. any ideas?
-
This reply was modified 4 years, 2 months ago by
vitalseeds.
-
This reply was modified 4 years, 2 months ago by
vitalseeds.
@stevegrunwell are you able to help me troubleshoot this? My customers are very frustrated in having to order during the night, as we hit our limit in the morning every day
@vitalseeds Apologies for the delay, messages tend to get buried when they’re in already-closed threads. In the future, please open a new thread ??
The transient will automatically re-create itself, which is to be expected. What *should* change, however, is the expiration time, and it certainly shouldn’t be expired as soon as it’s created.
Doing a bit of debugging, I was able to get this sorted out: depending on when the first order occurs, the logic would change:
The original version of the gist was set to 8:00pm (e.g. 20:00:00), but likely activated during regular business hours. Assuming an order came in at that time, the transient would be set and it wouldn’t be recalculated until the next time the interval resets.
In your case, you were starting the interval at 7am (e.g. 07:00:00), but likely putting it into effect during business hours. The “-24 hours” trick worked for stores with later expirations, but not those with expirations in the earlier parts of the day.
Before:
// $hours = 20; Now: Thu, 04 Feb 2021 16:00:00 +0000" Started: Wed, 03 Feb 2021 20:00:00 +0000" Resets: Thu, 04 Feb 2021 20:00:00 +0000" // $hours = 7; Now: Thu, 04 Feb 2021 16:00:00 +0000" Started: Wed, 03 Feb 2021 07:00:00 +0000" Resets: Thu, 04 Feb 2021 07:00:00 +0000"
After:
// $hours = 20; Now: Thu, 04 Feb 2021 16:00:00 +0000" Started: Wed, 03 Feb 2021 20:00:00 +0000" Resets: Thu, 04 Feb 2021 20:00:00 +0000" // $hours = 7; Now: Thu, 04 Feb 2021 16:00:00 +0000" Started: Thu, 04 Feb 2021 07:00:00 +0000" Resets: Fri, 05 Feb 2021 07:00:00 +0000"
I’ve updated the gist to account for this change, and my apologies for any frustrations your customers endured.
Hi Steve
Thanks for getting back to me. I had not realized the thread was closed!
Thanks also for trouble shooting this, do i just copy and paste the text above into the original filter somewhere? And if so where?
Fred
I’d start by grabbing a fresh copy of the gist and replacing the version you have currently, then updating the
$hours
variable accordingly.The latest version of the gist has the updated logic, but the customization will be the same as before (
$hours
,$minutes
, and$seconds
variables); in your case, this will be updating$hours
to 7.Ah ok, i understand, thanks a lot Steve, i appreciate your help with this.
Fred
-
This reply was modified 4 years, 2 months ago by
- The topic ‘Custom Order Reset time’ is closed to new replies.