There is a formula that works in all degrees, not just imaginary quadratic. In a global field $K$, let $O$ be integral over ${\mathbf Z}$ or ${\mathbf F}[t]$ (${\mathbf F}$ a finite field) and be "big", i.e., it has fraction field $K$. Let $\mathfrak c$ be the conductor ideal of $O$ in its integral closure $R$. Then
$$h(O) = \frac{h(R)}{[R^\times:O^\times]}\frac{\varphi_{R}({\mathfrak c})}{\varphi_O(\mathfrak c)},$$
where $\varphi_O(\mathfrak c)$ is the number of units in $O/\mathfrak c$ and $\varphi_R(\mathfrak c)$ is the number of units in $R/\mathfrak c$. This is derived in Neukirch's alg. number theory book in the number field case, but it goes through to any one-dimensional Noetherian domain with a finite residue rings and a finite class group.
In the imag. quadratic case the unit index $[R^\times:O^\times]$ is 1 most of the time so you don't notice it.

Both $\varphi_R(\mathfrak c)$ and $\varphi_O(\mathfrak c)$ can be written in the form ${\text N}(\mathfrak c)\prod_{\mathfrak p \supset \mathfrak c}(1 - 1/{\text{N}(\mathfrak p)})$, where the ideal norm $\text N$ means the index in $R$ or $O$ and $\mathfrak p$ runs over primes in $R$ or $O$ for the two cases.