Last active
September 7, 2020 06:47
-
-
Save Balakrishnan-flycart/e3142ad8ed44fde8c51b325d6d4b87fb to your computer and use it in GitHub Desktop.
Discount rules v2: WooCommerce Product Add Ons, by WooCommerce - fix for price with comma,dot,space separator
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
| add_action( 'wp_head', function () { | |
| $currency_code = '$'; | |
| if(function_exists('get_woocommerce_currency_symbol')){ | |
| $currency_code = html_entity_decode(get_woocommerce_currency_symbol()); | |
| } | |
| ?> | |
| <script type="application/javascript"> | |
| (function ($) { | |
| $(document).ready(function ($) { | |
| var currency_string = '<?php echo $currency_code; ?>'; | |
| var $form = jQuery('form.cart').first(); | |
| /** | |
| * Strikeout for option title | |
| * */ | |
| $('.product-addon .amount').each(function(){ | |
| var $targets = $(this); | |
| $lock = $targets.attr('data-lock'); | |
| if($lock === undefined || $lock === null){ | |
| $lock = false; | |
| } | |
| if($lock == false){ | |
| var price = newText = $(this).text().replace(currency_string, ''); | |
| price = price.replace(".", ''); | |
| price = price.replace(" ", ""); | |
| price = price.replace(",", '.'); | |
| console.log(price); | |
| var option = { | |
| custom_price: price, | |
| original_price: price | |
| }; | |
| $targets.attr('data-lock', true); | |
| $.AdvanceWooDiscountRules.getDynamicDiscountPriceFromCartForm($form, $targets, option); | |
| } | |
| }); | |
| $(document.body).on( "advanced_woo_discount_rules_on_get_response_for_dynamic_discount", function ( e, response, target, options ) { | |
| if(response.success == true){ | |
| var price_html = '' | |
| if(response.data !== undefined){ | |
| if(response.data.initial_price_html !== undefined && response.data.discounted_price_html !== undefined){ | |
| price_html += '<del>'+response.data.initial_price_html+'</del>'; | |
| price_html += ' <ins>'+response.data.discounted_price_html+'</ins>'; | |
| target.html(price_html); | |
| } | |
| } | |
| } | |
| target.attr('data-lock', false); | |
| }); | |
| /** | |
| * Strikeout for option values and subtotal | |
| * */ | |
| $form.on('updated_addons', function () { | |
| setTimeout(function () { | |
| $('.product-addon-totals .amount').each(function(){ | |
| var $targets = $(this); | |
| $lock = $targets.attr('data-lock'); | |
| if($lock === undefined || $lock === null){ | |
| $lock = false; | |
| } | |
| if($lock == false){ | |
| var price = newText = $(this).text().replace(currency_string, ''); | |
| price = price.replace(".", ""); | |
| price = price.replace(" ", ""); | |
| price = price.replace(",", '.'); | |
| console.log(price); | |
| var option = { | |
| custom_price: price, | |
| original_price: price | |
| }; | |
| $targets.attr('data-lock', true); | |
| $.AdvanceWooDiscountRules.getDynamicDiscountPriceFromCartForm($form, $targets, option); | |
| } | |
| }); | |
| }, 0); | |
| }); | |
| }); | |
| })(jQuery); | |
| </script> | |
| <?php } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment