If foo is important, then it should be configured in the script. This I think is good practice, because you then EXPLICITLY peg it to the script. I do not like indirection, implicit or hidden stuff ... scripts should be very simple if they are to be deployed.
Otherwise if you insist on finding it, then it can be found by doing
whereisfoo="$(which foo)"
whereisfoo="$(which foo)"
If this is not enough, then I fear what you may be doing is too complex.