If anyone has already applied this code, please note that I forgot to paste a critical part and I had to update it to encase the min_quantity assignment in
if ($product) {.
If you don't do this then $product will always evaluate to true in subsequent IF conditionals regardless of whether a product was actually found.