WooCommerce Product Add Ons with Woocommerce product table, by WooCommerce

Compatibility with WooCommerce Product Add Ons with WooCommerce Product Table by WooCommerce.

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 awdr_compatible_with_product_addon_and_table = function () {
					var currency_string = '<?php echo $currency_code; ?>';
					var $forms = jQuery('form.cart');
					$forms.each(function(){
						var $form = $(this);
						/**
                                     * Strikeout for option title
                                     * */
						$('.product-addon .amount, .wcpt-modal .product-addon-totals .wc-pao-col2 > strong').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, '');
								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, .wcpt-modal .product-addon-totals .wc-pao-col2 > strong').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, '');
										var option = {
											custom_price: price,
											original_price: price
										};
										$targets.attr('data-lock', true);
										$.AdvanceWooDiscountRules.getDynamicDiscountPriceFromCartForm($form, $targets, option);
									}
								});
							}, 0);
						});
					});
				};
				awdr_compatible_with_product_addon_and_table();
				$( document ).ajaxComplete(function( event, xhr, settings ) {
					if(settings.data != ''){
						var query_string = settings.data;
						if(typeof query_string == 'string'){
							var query_string_to_check = 'action=wcpt_get_product_form_modal';
							if(query_string.indexOf(query_string_to_check) != -1){
								awdr_compatible_with_product_addon_and_table();
							}
						}
					}
				});
				$(document).on('change', 'input.wc-pao-addon-field, textarea.wc-pao-addon-field, select.wc-pao-addon-field, .variations select', function (){
					awdr_compatible_with_product_addon_and_table();
				});
			});

		})(jQuery);
</script>
<?php } );