Jump to content
DennisMidjord

Hook to cancel invoices for terminated products

Recommended Posts

Don't know if this is the right category to post this in, but I thought I wanted to share this.

It's a very small hook that cancels an invoice once the product gets terminated.

//<?php

use WHMCS\Database\Capsule;
add_hook('PreModuleTerminate', 1, function($vars) {
	$invoiceid = Capsule::table('tblinvoiceitems')
		->where('relid', '=', $vars['params']['serviceid'])
		->orderBy('duedate', 'desc')
		->first();
	Capsule::table('tblinvoices')
		->where('id', '=', $invoiceid->invoiceid)
		->update(['Status' => 'Cancelled']);
});

Any feedback is much appreciated.

  • Thanks 1

Share this post


Link to post
Share on other sites
//Updated to only target products of Hosting-type.
<?php
use WHMCS\Database\Capsule;
add_hook('PreModuleTerminate', 1, function($vars) {
	$invoiceid = Capsule::table('tblinvoiceitems')
		->where('relid', '=', $vars['params']['serviceid'])
                ->where('type','Hosting')
		 ->orderBy('duedate', 'desc')
		->first();
	Capsule::table('tblinvoices')
		->where('id', '=', $invoiceid->invoiceid)
		->update(['Status' => 'Cancelled']);
});

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines