I added couple things:

* all() instead of having nested conditionals.
* Using the lookup function to help to get the category code.
* breaking out of the for loop once the correct price_id is found to prevent un-needed cycles