Support » Plugin: Limit Orders for WooCommerce » Custom Order Reset time

  • Resolved proexcell88

    (@proexcell88)


    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…

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Steve Grunwell

    (@stevegrunwell)

    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)?

    Plugin Author Steve Grunwell

    (@stevegrunwell)

    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

    Plugin Author Steve Grunwell

    (@stevegrunwell)

    @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.

    Plugin Author Steve Grunwell

    (@stevegrunwell)

    Awesome, glad to hear it!

    vitalseeds

    (@vitalseeds)

    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 plugin

    Do you have any idea what is happening here?

    Fred

    Plugin Author Steve Grunwell

    (@stevegrunwell)

    @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 6 days, 21 hours ago by vitalseeds.
    • This reply was modified 6 days, 21 hours 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

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.