Standard texts prove that $\textrm{ord}_n(ab)=\textrm{ord}_n(a)\,\textrm{ord}_n(b)$ when $\textrm{gcd}(\textrm{ord}_n(a),\textrm{ord}_n(b))=1$. What if they are not relatively prime? Here $\textrm{ord}_n(b)$ is the multiplicative order of $b$, i.e. the smallest positive integer $m$ such that $b^m=1 (\textrm{mod}\,n)$.
The naive guess that $\textrm{ord}_n(ab)$ is $\textrm{lcm}(\textrm{ord}_n(a),\textrm{ord}_n(b))$ can not be right since it gives $\textrm{ord}_n(b^k)=\textrm{ord}_n(b)$, whereas in fact $\textrm{ord}_n(b^k)=\frac{\textrm{ord}_n(b)}{\textrm{gcd}(\textrm{ord}_n(b),k)}$. So the order of the product must depend on more than just orders of the factors, perhaps on something in their prime factorizations?
What does it depend on exactly? Is there a formula for the general case? If not, are there formulas for some special cases, e.g. when $a,b$ are relatively prime, square-free, prime powers, when $n$ is prime, etc.? Are there useful bounds for it? Since the product of orders is always an upper bound a lower bound would be interesting. References appreciated.