This can be done where either the Product is moved as a Linked Product or moved totally to another Category ...

You need to customize the orders class for this to work ...

NOTE: there are no overrides for the orders class ... so backup your original code and your changes for when you do future upgrades ...