"Only if" and "if only" are idiomatic phrases that are quite different in meaning.
"If" is used to express a condition. When used after only i.e. only if, it expresses a strong condition or the only situation in which something can happen. A few examples of its use are given below:
1- I'll come to the party only if I can bring my friend with me.
2- you will get your payment only if you complete the work.
We use the phrase "if only" to wish that something was true or something had happened. Please look at the following examples:
1- If only I were rich.
2- If only I were not so fat, I would be able to get into these trousers.