How can I edit variant cycle to consider stock availability in coding?

Hi all,

my theme is set to display the combo of the variants in the item card, regardless of whether they actually have availability in stock or not.
I would like to implement the cycle no longer taking into consideration only product.options_with_values ​​but also if stock> 0.

Any idea?

A thousand thanks