add to cart button on collection pages doesn't work with variants

Hello, my shop is https://www.infinitycosmetics.it/ ENVY THEME

I have an add to cart button in collection pages, I added this code in product-grid–indiv-product.liquid file:

But this code doesn’t work for unavailable variants: if first variant is unavailable, add to cart button is inactive and customers can’t add to cart other available variants, if first variant is available, add to cart button is active but customers can add to cart also unavailable variants.

Anyone can help me?

This is the first solution I’ve seen for an add to cart code on the collection page in envy, but I also have variants and this looks like it won’t work 100%. Have you found a solution?