I think i have found a little problem in your mod which makes it kind of not usable [at least for us i think]
I noticed that the discount is being applied to anything , as in apllied to products which doesn''t even have been payed.
Situation.
i order for say an amount of 100 dollars.
[i don't pay the bill, but it just sits ther with status - waiting for payment]
Then the next order i do - a couple of days later i get a predifined discount because i have "spent" 100 dollars which applies for a discount.
HOWEVER, i have not payed the first order and i will never do, but still i receive the discount.
Do you see where i am going to?
The discount should be applied only when the status has been set to.
Package shipped / payment received , whatever.
Thus only when the transaction truly has been done and not on a waiting basis.
In this case, one can just aim for the highest discount by first placing a huge order and not paying this order , and then just make a second very small order , and recieve the discount straight away.
Very cool for clever dishonost "loyal" customers, but highly unusable in a trusted environment.
Could this little "error" be fixed in some way ?