In v8.10 we added the ability to automatically cancel invoices once they reach x days overdue.

To achieve cancellation of overdue invoices once a service is terminated, configure the Days Overdue setting to the same value as the Termination Days setting.

https://docs.whmcs.com/system/automation/automation-settings/#billing-settings