<script>
jQuery(val).each(function( index,value) {
let price_1 = jQuery(value).find('.woocommerce-Price-amount.amount:first').attr('data-orig-price') / data;
let price_2 = jQuery(value).find('.woocommerce-Price-amount.amount:last').attr('data-orig-price') / data;
if(valute_text == '₽'){
price_1 = price_1.toFixed(0);
price_1 = String(price_1).replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1 ');
price_2 = price_2.toFixed(0);
price_2 = String(price_2).replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1 ');
}else {
price_1 = price_1.toFixed(2)
price_2 = price_2.toFixed(2)
}
jQuery(value).find('.woocommerce-Price-amount.amount:first').text(price_1 + valute_text)
jQuery(value).find('.woocommerce-Price-amount.amount:last').text(price_2 + valute_text)
});
</script>
['first', 'last'].forEach(term => {
jQuery(val).each((index, value) => {
const elem = jQuery(value).find(`.woocommerce-Price-amount.amount:${term}`);
let price = elem.attr('data-orig-price') / data;
price = ((valute_text === '₽')
? price.toFixed(0).toString().replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1 ')
: price.toFixed(2));
elem.text(price + valute_text);
});
});
const selector = '.woocommerce-Price-amount.amoun';
jQuery(val).each(function (index, value) {
const price_selector_1 = jQuery(value).find(selector + ':first');
const price_selector_2 = jQuery(value).find(selector + ':last');
let price_1 = getBasePrice(price_selector_1, data);
let price_2 = getBasePrice(price_selector_2, data);
if (valute_text === '₽'){
price_1 = changePriceWithRouble(price_1);
price_2 = changePriceWithRouble(price_2);
} else {
price_1 = price_1.toFixed(2);
price_2 = price_2.toFixed(2);
}
setViewPrice(price_selector_1, price_1, valute_text);
setViewPrice(price_selector_2, price_2, valute_text);
});
function getBasePrice (element, data) {
return element.attr('data-orig-price') / data;
}
function changePriceWithRouble (price) {
return String(price_1.toFixed(0)).replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1 ');;
}
function setViewPrice (element, price, text) {
element.text(price + text);
}