Jump to content

Defer payment


Mytihost

Recommended Posts

Hey All

Looking for some advice. I currently sell a product with monthly and yearly billing. Currently on the first month they get a 100% discount off the first months subscription to evaluate the service free of charge. 

 

My issue is yearly I would  like to affectively do the same.

The idea is if someone purchases a yearly plan they get 1 free month to evaluate the service.

Example someone placed an order today the product would be set up today. However invoice and payment would then be due the following month on the 2nd March for the year.

Is this achievable using a hook

I know I can create a trial product for evaluation purposes but I would rather not have to create a separate product if I can defer invoice payment to the following month this would then essentially be there evaluation period.

 

Thanks

Link to comment
Share on other sites

Try something like this: 

<?php
/**
 * WHMCS Hook: Add 1 month to Next Due Date
 * Only runs for a specific product after provisioning
 *
 * Trigger: AfterModuleCreate
 */

use WHMCS\Database\Capsule;

add_hook('AfterModuleCreate', 1, function ($vars) {

    // CHANGE THIS to your target Product ID
    $targetProductId = 123;

    $serviceId = (int) ($vars['serviceid'] ?? 0);
    if (!$serviceId) {
        return;
    }

    $service = Capsule::table('tblhosting')
        ->where('id', $serviceId)
        ->first();

    if (
        !$service ||
        (int) $service->packageid !== $targetProductId ||
        empty($service->nextduedate)
    ) {
        return;
    }

    $nextDue = new DateTime($service->nextduedate);
    $nextDue->modify('+1 month');

    Capsule::table('tblhosting')
        ->where('id', $serviceId)
        ->update([
            'nextduedate' => $nextDue->format('Y-m-d'),
        ]);
});

Change 123 to your specific product ID.

Edited by RadWebHosting
specific product use case
Link to comment
Share on other sites

On 2/4/2026 at 11:12 AM, RadWebHosting said:

Try something like this: 

<?php
/**
 * WHMCS Hook: Add 1 month to Next Due Date
 * Only runs for a specific product after provisioning
 *
 * Trigger: AfterModuleCreate
 */

use WHMCS\Database\Capsule;

add_hook('AfterModuleCreate', 1, function ($vars) {

    // CHANGE THIS to your target Product ID
    $targetProductId = 123;

    $serviceId = (int) ($vars['serviceid'] ?? 0);
    if (!$serviceId) {
        return;
    }

    $service = Capsule::table('tblhosting')
        ->where('id', $serviceId)
        ->first();

    if (
        !$service ||
        (int) $service->packageid !== $targetProductId ||
        empty($service->nextduedate)
    ) {
        return;
    }

    $nextDue = new DateTime($service->nextduedate);
    $nextDue->modify('+1 month');

    Capsule::table('tblhosting')
        ->where('id', $serviceId)
        ->update([
            'nextduedate' => $nextDue->format('Y-m-d'),
        ]);
});

Change 123 to your specific product ID.

Hi thank you for the input

Im looking to achieve it on first point of purchase. 

Idea is when they purchase a yearly plan as normal it will stop invoice generation or modify the invoice set it to zero giving them essentially a one month trial before they commit to the yearly subscription. The first real invoices will be sent the following month for the year subscription. 

 

Maybe im over thinking it. Looking for a work around so I dont need to create trial products.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated