-
-
Save Balakrishnan-flycart/4a7af0cf47c699812b82a39d770c00d1 to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Exclude discount for add on price compatible for YITH WooCommerce Product Add-ons & Extra Options (Product page strike out)
This file contains 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
add_action( 'wp_footer', function () { | |
$currency_code = '$'; | |
if(function_exists('get_woocommerce_currency_symbol')){ | |
$currency_code = html_entity_decode(get_woocommerce_currency_symbol()); | |
} | |
?> | |
<script type="application/javascript"> | |
function compatiblePriceStrikeOut() { | |
var $form = jQuery('form.cart').first(); | |
var $targets = ''; | |
var option = { | |
custom_price: parseFloat(jQuery('.yith_wapo_group_total').data('product-price')), //get current product price | |
original_price: parseFloat(jQuery('.yith_wapo_group_total').data('product-price')), | |
}; | |
jQuery.AdvanceWooDiscountRules.getDynamicDiscountPriceFromCartForm($form, $targets, option); | |
jQuery(document.body).on("advanced_woo_discount_rules_on_get_response_for_dynamic_discount", function (e, response, target, options) { | |
if (response.success == true) { | |
var currency_string = '<?php echo $currency_code; ?>'; | |
var quantity = jQuery('form.cart').first().find('input[name="quantity"]').val(); | |
quantity = parseInt(quantity); | |
var price_html = '' | |
if (response.data !== undefined) { | |
if (response.data.initial_price_html !== undefined && response.data.discounted_price_html !== undefined) { | |
var option_total = jQuery('div.yith_wapo_group_option_total span.price.amount').text().replace(currency_string, ''); | |
var per_product_discounted_price = parseFloat(response.data.discounted_price).toFixed(2); | |
var per_product_price = parseFloat(response.data.initial_price).toFixed(2); | |
var discount_price_for_qty = per_product_discounted_price * quantity; | |
var price_for_qty = per_product_price * quantity; | |
var option_total_for_qty = parseFloat(option_total); | |
var total = option_total_for_qty + discount_price_for_qty; | |
if(isNaN(price_for_qty) || isNaN(discount_price_for_qty) || isNaN(total)){ | |
return; | |
} | |
price_html += '<del>' + currency_string + parseFloat(price_for_qty).toFixed(2) + '</del>'; | |
price_html += ' <ins>' + currency_string + parseFloat(discount_price_for_qty).toFixed(2) + '</ins>'; | |
var total_html = currency_string + parseFloat(total).toFixed(2); | |
jQuery('div.yith_wapo_group_product_price_total').html("<span class='price amount'>" + price_html + "</span"); | |
jQuery('div.yith_wapo_group_final_total').html("<span class='price amount'>" + total_html + "</span"); | |
} | |
} | |
} | |
}); | |
} | |
jQuery(document).ready(function () { | |
compatiblePriceStrikeOut(); | |
}); | |
jQuery(document).on('yith-wapo-product-option-update yith-wapo-product-price-changed', function () { | |
setTimeout(function(){ compatiblePriceStrikeOut(); }, 1000); | |
}); | |
</script><?php | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment