Dkuzik Posted January 25 Share Posted January 25 hello, I have a product lets say it is 3 day free trial. i want to create a hook that runs module command renew xxx times. so i make the trial 6,9,12 day trials. my module only allows 3 days that is why i want to create a hook that renews on module create. just can't figure out how to get renew to work. 0 Quote Link to comment Share on other sites More sharing options...
Slaweally Posted January 26 Share Posted January 26 <?php use WHMCS\Database\Capsule; add_hook('AfterModuleCreate', 1, function($vars) { // Get the service ID and product ID $serviceId = $vars['serviceid']; $productId = $vars['pid']; // Check if the product matches the target product ID (e.g., 3-day free trial product) $targetProductId = 123; // Replace with your trial product's ID if ($productId == $targetProductId) { // Define how many renew cycles you want (e.g., 2 renews = 3 + 3 + 3 days = 9 days total) $renewCycles = 2; for ($i = 0; $i < $renewCycles; $i++) { try { // Trigger the ModuleRenew command localAPI('ModuleRenew', [ 'serviceid' => $serviceId, ]); logActivity("Renewal successful for Service ID: {$serviceId} (Cycle: " . ($i + 1) . ")."); } catch (Exception $e) { logActivity("Renewal failed for Service ID: {$serviceId} (Cycle: " . ($i + 1) . "): " . $e->getMessage()); } } } }); 0 Quote Link to comment Share on other sites More sharing options...
Dkuzik Posted January 29 Author Share Posted January 29 thank you but I couldn't get this to work. I have something simular. I think product ids and service ids not being passed through 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.