The script below shows how to add a sold out badge in Shopify
<script>
var __isp_options = {
isp_serp_with_product_attributes: 1,
isp_serp_callback: function (data) {
for (const key in ISP_PRODUCTS) {
const product = ISP_PRODUCTS[key];
const $gridItem = $(`.isp_grid_product[product_id="${key}"]`);
// set badges
Badges.create(product, $gridItem);
}
}/* end of isp_serp_callback*/
};
const Badges = {
create: (product, $gridItem) => {
if ($gridItem.hasClass("inventory")) return;
$gridItem.addClass("inventory");
Badges.set(product, $gridItem);
},
set: (product, $gridItem) => {
if($gridItem.find(".isp-custom-badge").length > 0) return;
if(Badges.isSoldOut(product)){
$gridItem.prepend(`<span class="isp-custom-badge Sold-out">Sold Out</span>`);
}
},
isSoldOut: (product) => {
return ("iso" in product && product.iso)
},
};
</script>
<style>
/* Badges */
.isp-custom-badge {
display: flex;
position: absolute;
font-weight: 400;
font-style: normal;
z-index: 1;
top: 10px;
right: 10px;
min-width: 8vw;
height: 30px;
padding: 0 30px 0 30px;
margin: 0 0 0 0;
align-items: center;
justify-content: center;
font-size: 16px;
font-family: "proxima-nova";
line-height: 30px;
text-align: center;
white-space: normal;
border-radius: 15px;
}
.isp-custom-badge.Sold-out {
color: #fff;
background-color: #2263b2;
}
</style>