<script>
$( document ).ready(function() {

	const breadcrumbs = $(".br-link");

	breadcrumbs.each(function(idx, b) {
		const breadcrumbText = b.innerText;
		b.innerHTML = `<span itemprop=\"name\">${breadcrumbText}</span>`;
	})

	const lastBreadcrumb = $(".br-text")[0]
	if(lastBreadcrumb) {
		const breadcrumbText = lastBreadcrumb.innerText;
		lastBreadcrumb.innerHTML = `<span itemprop=\"name\">${breadcrumbText}</span>`;
	}

	const postImages = $(".post-div-blog img");
	postImages.each(function(idx, img) {
		img.setAttribute("itemprop", "image");
	})
	const isVariable = $(".variations").length > 0;

	function replacer(match, p1, p2, offset, string) {
		let price = p1.replace(" ", "");
		return `<bdi><span itemprop=\"price\" content=\"${price}\">${p1}</span>&nbsp;<span itemprop=\"priceCurrency\" class=\"woocommerce-Price-currencySymbol\">${p2}</span></bdi>`
	}

	if(isVariable) {
		setTimeout(() => {
			const priceDiv = $(".prod-div .woocommerce-Price-amount").eq(0);
			const oldMarkup = $(".prod-div .woocommerce-Price-amount")[0].innerHTML;
			// const newMarkup = oldMarkup.replace(/^<bdi>(.*)&nbsp;<span class="woocommerce-Price-currencySymbol">(.*)<\/span><\/bdi>/g, "<bdi><span itemprop=\"price\">$1</span>&nbsp;<span itemprop=\"priceCurrency\" class=\"woocommerce-Price-currencySymbol\">$2</span></bdi>");
			const newMarkup = oldMarkup.replace(/^<bdi>(.*)&nbsp;<span class="woocommerce-Price-currencySymbol">(.*)<\/span><\/bdi>/g, replacer);
			priceDiv.html(newMarkup);

		}, 2000)		
	} else {
		const priceDiv = $(".prod-div .woocommerce-Price-amount").eq(0);
		const oldMarkup = $(".prod-div .woocommerce-Price-amount")[0].innerHTML;
		// const newMarkup = oldMarkup.replace(/^<bdi>(.*)&nbsp;<span class="woocommerce-Price-currencySymbol">(.*)<\/span><\/bdi>/g, "<bdi><span itemprop=\"price\">$1</span>&nbsp;<span itemprop=\"priceCurrency\" class=\"woocommerce-Price-currencySymbol\">$2</span></bdi>");
		const newMarkup = oldMarkup.replace(/^<bdi>(.*)&nbsp;<span class="woocommerce-Price-currencySymbol">(.*)<\/span><\/bdi>/g, replacer);
		priceDiv.html(newMarkup);
	}
})
</script>