Hi,
First, I would recommend to check the settings of your menu item / module. In there, you'll find a "Which price" setting where you can select what prices you want to show for the products of the listing. You should make sure that you have it set to "range" so that you will have exactly two prices for each product. Otherwise, the if condition won't return true.
And you don't have to look for the variants prices. This is already handled automatically. If you have the setting above set to range, the system will do three things:
- load the prices of the main product
- if the main product doesn't have any price, load the prices of its variants instead
- select the minimum and maximum out of all these prices
So if it's configured properly, you should always get 2 prices, and you shouldn't have to use any other code than the code I gave in my first message on this thread.