Ian Mead Posted October 31, 2023 Share Posted October 31, 2023 Hi, Does anyone have a hook that would automatically remove incomplete/unpaid orders after a set time? Many thanks 0 Quote Link to comment Share on other sites More sharing options...
Solution leemahoney3 Posted November 2, 2023 Solution Share Posted November 2, 2023 I assume you only want this to happen on Pending unpaid orders? If so, the order needs to be cancelled before deleted. The below hook should work <?php use Carbon\Carbon; use WHMCS\Order\Order; add_hook('DailyCronJob', 1, static function () { $daysBeforeDeletion = 14; Order::where('status', 'Pending')->each(function (Order $order) use ($daysBeforeDeletion, &$orders) { if ($order->isPaid) { return; } if ($order->date->addDays($daysBeforeDeletion)->toDateString() > Carbon::now()->toDateString()) { return; } $cancelResult = localAPI('CancelOrder', ['orderid' => $order->id]); if ($cancelResult['result'] === 'success') { localAPI('DeleteOrder', ['orderid' => $order->id]); } }); }); Update the $daysBeforeDeletion variable to how many days you wish to keep the order after its order date before its deleted. This will run once a day on your WHMCS cron job. 2 Quote Link to comment Share on other sites More sharing options...
Ian Mead Posted November 3, 2023 Author Share Posted November 3, 2023 Hi Lee Thank you very much. I have implemented that now. Perfect solution. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.