$total isn't valid in this context

Check $discount_total against $sub_total instead of $total -- this seems appropriate given tax calculation, may want to check against $product['total'] instead?