Updated prevent_caching() method to work if a cart/checkout page isn't set.

Closes #6396