I have updated the code in your shared code. Please ask in the comments if you did not get changes.
add_action('wp_ajax_dynamic_price', 'get_update_dynamic_price_xyz');
add_action('wp_ajax_nopriv_dynamic_price', 'get_update_dynamic_price_xyz');
function get_update_dynamic_price_xyz()
{
global $product;
/**
* Get the discount details of given product with custom price
* @param $price float/integer
* @param $product object (Product object Example: wc_get_product($product_id))
* @param $quantity int
* @param $custom_price float/integer (0 for calculate discount from product price)
* @param $return_details string (Default value 'discounted_price' accepted values="discounted_price",'all')
* @param $manual_request boolean (Default value false: pass this as true for get discount even if there is no item in cart)
* @param $is_cart boolean (Default value true)
* @return array|float|int - is product has no discounts, returns $price;else return array of discount details based on $return_details
*/
$qty = $_POST['quantity'];
$price = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $product->get_price(), $product->get_id(), $qty, 0, 'discounted_price', 'true', 'true');
if ($price == '')
{
$price = $product->get_price();
}
echo $price;
}
function action_woocommerce_single_product_summary()
{
global $product;
/**
* Get the discount details of given product with custom price
* @param $price float/integer
* @param $product object (Product object Example: wc_get_product($product_id))
* @param $quantity int
* @param $custom_price float/integer (0 for calculate discount from product price)
* @param $return_details string (Default value 'discounted_price' accepted values="discounted_price",'all')
* @param $manual_request boolean (Default value false: pass this as true for get discount even if there is no item in cart)
* @param $is_cart boolean (Default value true)
* @return array|float|int - is product has no discounts, returns $price;else return array of discount details based on $return_details
*/
$price = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $product->get_price(), $product->get_id(), 1, 0, 'discounted_price', 'true', 'true');
if ($price == '')
{
$price = $product->get_price();
}
$currency_symbol = get_woocommerce_currency_symbol();
// let's setup our div
echo sprintf('<div id="product_total_price" style="margin-bottom:20px;">%s %s</div>', __('Product Total:', 'woocommerce'), '<span class="price">' . $currency_symbol . $price . '</span>');
?>
<script>
jQuery(function($) {
// jQuery variables
var price = <?php echo $price; ?>,
currency = '<?php echo $currency_symbol; ?>',
quantity = $('[name=quantity]').val();
// Code to run when the document is ready
var product_total = parseFloat(price * quantity);
$('#product_total_price .price').html(currency + product_total.toFixed(2));
// On change
$('[name=quantity]').change(function() {
var quantity = this.value;
$.ajax({
url: '<?php echo admin_url('admin-ajax.php') ?>',
type: 'POST',
data: {
quantity: quantity,
action: 'dynamic_price'
},
success: function(data) {
//var price = data;
alert('yes');
alert(data);
}
});
if (!(this.value < 1)) {
product_total = parseFloat(price * this.value);
$('#product_total_price .price').html(currency + product_total.toFixed(2));
}
});
});
</script>
<?php
}
// We are going to hook this on priority 31, so that it would display below add to cart button.
add_action('woocommerce_single_product_summary', 'action_woocommerce_single_product_summary', 31, 0);