Use the script to display the discount in percentage
<script>
var __isp_options = {
isp_serp_with_product_attributes: 1,
isp_serp_callback: function () {
// Add Sale Badge
$jquery_isp('li.isp_grid_product').each(function () {
if($(this).find(".sale-badge-container").length === 0) {
const productID = $(this).attr('product_id');
const badges = getProductBadges(productID);
if (badges)
$(this).find(".isp_product_image_wrapper").prepend(badges);
}
});
}
};
function roundSale (num, precision) {
num = parseFloat(num);
if (!precision) return num.toLocaleString();
return (Math.round(num / precision) * precision).toLocaleString();
}
function getProductBadges(productID) {
let content = '';
const originalPrice = parseFloat(ISP_PRODUCTS[productID].p);
const price = parseFloat(ISP_PRODUCTS[productID].p_c);
const sale_price = roundSale(((price - originalPrice) / price) * 100,1) + "%";
if(parseInt(sale_price) > 0) {
content += `<div class="isp-custom-badge.sale">${sale_price}</div>`;
}
return content ? `<div class="sale-badge-container">${content}</div>` : null
}
</script>