Moving check to top of foreach and including variable if multiple orders