Created
August 3, 2021 07:29
-
-
Save Balakrishnan-flycart/f8db9aba137a14890fc68b1394cdc114 to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Remove out of stock item and disabled variants in change variants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment