Hello! Great question!! So in either instance, whether you know if the person bought the food or not, you can ask them, "Did you buy food?". If you knew that the person bought food, you wouldn't ask them if they bought food, you would ask "What did you buy?" as saying what kind of food or which food did you buy.
Hope this helps!!