  For arithmetic applications, we extend and refine our results in \cite{YZ} to
allow ramifications in a minimal way. Starting with a possibly ramified
quadratic extension $F'/F$ of function fields over a finite field in odd
characteristic, and a finite set of places $\Sigma$ of $F$ that are unramified
in $F'$, we define a collection of Heegner--Drinfeld cycles on the moduli stack
of $\mathrm{PGL}_{2}$-Shtukas with $r$-modifications and Iwahori level
structures at places of $\Sigma$. For a cuspidal automorphic representation
$\pi$ of $\mathrm{PGL}_{2}(\mathbb{A}_{F})$ with square-free level $\Sigma$,
and $r\in\mathbb{Z}_{\ge0}$ whose parity matches the root number of $\pi_{F'}$,
we prove a series of identities between: (1) The product of the central
derivatives of the normalized $L$-functions $\mathcal{L}^{(a)}(\pi,
1/2)\mathcal{L}^{(r-a)}(\pi\otimes\eta, 1/2)$, where $\eta$ is the quadratic
id\`ele class character attached to $F'/F$, and $0\le a\le r$; (2) The self
intersection number of a linear combination of Heegner--Drinfeld cycles. In
particular, we can now obtain global $L$-functions with odd vanishing orders.
These identities are function-field analogues of the formulas of Waldspurger
and Gross--Zagier for higher derivatives of $L$-functions.
