Remove out of stock item and disabled variants in change variants

Remove out-of-stock items and disabled variants when changing variants.

<?php
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
//override path: yourtheme/woo-discount-rules-pro/buy-x-get-y-select-auto-add-variant.php
?>
<div class="awdr-select-free-variant-product-toggle"><?php _e('Change Variant', 'woo-discount-rules-pro') ?></div>
<div class="awdr-select-variant-product">
<?php
foreach ($available_products as $available_product) { //parent_id
    if ($available_product != $customer_product_choice['chosen']) {
        $product_variation = new WC_Product_Variation( $available_product );
        // get variation featured image
        $variation_image = $product_variation->get_image(array( 50, 50));
        $stock = false;
        $managing_stock = $product_variation->managing_stock();
        $visible_variation = $product_variation->variation_is_visible();
        if($managing_stock){
            $stock_quantity = $product_variation->get_stock_quantity();
            if(($stock_quantity > 0) && $visible_variation){
                $stock = true;
            }
        }else{
            if($visible_variation){
                $stock = true;
            }
        }
        
        if(!$stock){
            continue;
        }

        ?>
        <div class="awdr_free_product_variants">
            <span class="awdr_change_product" data-pid="<?php echo $available_product; ?>"
                data-rule_id="<?php echo $customer_product_choice['matched_rule_identification']; ?>"
                data-parent_id="<?php echo $customer_product_choice['parent_product_id']; ?>"><span class="awdr_variation_image"><?php echo $variation_image; ?></span><span class="awdr-product-name"><?php echo  get_the_title($available_product); ?></span></span>
        </div>
        <?php
    }
}
?>
</div>