الكود بالكامل
<script type="text/javascript">
$(document).ready(function(){
//get product bar offsit
const mm = $("#product .price").offset() ;
//make offset
const newoffset= mm.top - 100;
//get currency
const currency = "<?php echo $currency ?>" ;
//lets make array for total price
const totalPrice = {};
//get product price
const regex = /[+-]?\d+(\.\d+)?/g;
const price = Number($('#price').text().match(regex)[0]);
console.log(price);
const discount = /"quota":([0-9.]+)([^}]*)"discount":([0-9.]+)/g;
//get the radio elemnt
var element = $('input[type="radio"]');
//lets play with code
$(element).click(function(){
//get product option price
var optionPrice = '';
if($(this).context.alt){
optionPrice = Number($(this).context.alt.match(regex)['0']);
}else{
optionPrice = Number(0);
}
//get product option id to sum only one time
var OprionId =$(this).context.name;
//add option price by option id
totalPrice[OprionId] = +optionPrice ;
totalPrice['product'] = price;
//lets take total = 0
var total = 0 ;
//array loop
for(var key in totalPrice){
total= total + totalPrice[key];
}
var totalTax = total*(5/100);
$('html, body').animate({ scrollTop: newoffset});
$('#price').animate( {'opacity': 0}, 400, function(){
$(this).text(currency+" "+total.toFixed(2)).animate({'opacity': 1}, 400) ; });
$('#OnlyTax').animate({'opacity': 0}, 400, function(){
$(this).text(currency+" "+totalTax.toFixed(2)).animate({'opacity': 1}, 400); });
});
});
</script>