Many people switch “that” and “which” in their sentences. I think the schoolmarms in Britain teach something opposite from the US usage, which doesn’t help. (Note that correct usage.)
Here’s how we do it and why:
“That” is a defining or restrictive pronoun.
Example: “The well that is in the middle of the field is producing only gas.”
It defines which well out of a choice of several wells is producing gas.
“Which” is an undefined or unrestricted pronoun.
Example: “The well, which is in the middle of the Gulf of Mexico, is producing gas.”
You already know which well is being discussed, and the phrase after the “which” merely adds a little extra information that folks in Louisiana might call “lagniappe.”
Fun Fact: A baker’s dozen = 13, and that extra donut would be lagniappe, which means a little something extra. Some folks call that “gravy.” Folks my age call that “groovy.”
Golden Rule: Always use a comma before “which” and never use a comma before “that.”