Comma before "then"

Obey your manual of style, either the one you've chosen or the one thrust upon you. I use The Chicago Manual of Style, which recommends that you separate an introductory dependent clause (here, your if) from the main clause.