The way I found to get old coffee and tea stains out of my carpet is to mix 1 tablespoon of liquid dish soap, 1 tablespoon of white vinegar and 2 cups of warm water together in bucket.
Then get a sponge and dip the sponge in the water with the mixture and then blot the area where the coffee or tea stains are.
Then rub the sponge over the stain a few times and then use a cloth to blot the area again and the stains should start to lift.
If not you may need to mix some baking soda and water or vinegar together and then the coffee or tea stains should lift.
Or try a carpet cleaner or upholstery cleaner to help suck up the stain residue.