jQuery(document).ready(function ($){
function updatePrice(){
$.ajax({
url: gold_ajax.ajaxurl,
type: "POST",
data: {
action: "update_dynamic_price",
},
success: function (response){
if(response.data.goldPrice){
$(".gold-price-val").html(response.data.goldPrice);
$(".gold-price-val")
.closest(".price-head-wrap")
.find(".rate-arrow")
.addClass(response.data.gold_class);
$(".gold-price-val")
.closest(".price-head-wrap")
.find(".price-new")
.html(response.data.live_gold);
}
if(response.data.silverPrice){
$(".silver-price-val").html(response.data.silverPrice);
$(".silver-price-val")
.closest(".price-head-wrap")
.find(".rate-arrow")
.addClass(response.data.silver_class);
$(".silver-price-val")
.closest(".price-head-wrap")
.find(".price-new")
.html(response.data.live_silver);
}
if(response.data.platinumPrice){
$(".platinum-price-val").html(response.data.platinumPrice);
$(".platinum-price-val")
.closest(".price-head-wrap")
.find(".rate-arrow")
.addClass(response.data.platinum_class);
$(".platinum-price-val")
.closest(".price-head-wrap")
.find(".price-new")
.html(response.data.live_platinum);
}},
});
}
updatePrice();
function updatePrices(){
$.ajax({
url: gold_ajax.ajaxurl,
type: "POST",
data: {
action: "update_dynamic_price",
},
success: function (response){
if(response.data.goldPrice){
$(".gold-summary-price").html("S" + response.data.goldPrice);
$(".gold-change")
.removeClass("positive negative")
.addClass(response.data.gold_class==="pos" ? "positive":"negative"
)
.html((response.data.live_gold > 0 ? "+":"") +
response.data.live_gold +
"%"
);
}
if(response.data.silverPrice){
$(".silver-summary-price").html("S" + response.data.silverPrice
);
$(".silver-change")
.removeClass("positive negative")
.addClass(response.data.silver_class==="pos" ? "positive":"negative"
)
.html((response.data.live_silver > 0 ? "+":"") +
response.data.live_silver +
"%"
);
}},
});
}
updatePrices();
if($(".price-box").length > 0){
setInterval(updatePrice, 60000);
}});