Showing variant price on out of stock items and refreshing on variant selection

Hello friendly Shopify community! I used a piece of code found here on an old thread to add a small feature to my site - showing variant price for out of stock items (added red code below).

<span class="sold_out">{% if variant.available == false %}{{ 'products.product.sold_out' | t }} - {{ variant.price | money }} {% endif %}</span>

This works great but unfortunately theres a UiUx bug in that this variant price does not update when a new variant is selected via the dropdown option picker. Looking into it more, it seems like the details only refresh if there is at least one variant for the product currently in stock, otherwise nothing refreshes.

What JS change do I need to make to ensure the details refresh when a new variant is selected (even on out of stock items)?