tjordan
tjordan

Reputation: 19

insert product price into Offers schema meta tag using javascript

Editing my original question: Thanks, I tried the suggested code copied from the suggested post:

First problem is it has an error in the syntax. I believe it should be have a closing bracket right after price.

But, it isn't changing the content field in the price meta.

This is what I have:

    <script type="text/javascript">
    strhtmlprice = "<%=getCurrentAttribute('item','salespriceHTML')%>";
    strhtmlprice = strhtmlprice .replace("$", "");
    strhtmlprice = strhtmlprice .replace(",", "");
    document.querySelector("meta[name='price']").setAttribute("content", 
    strhtmlprice);
    </script>

Does the script go above the schema section of does it not matter?

I am building an Offers schema in my ecommerce site and want to insert the product price into it. I verified I am getting the price from the database but can't figure out how I can get the value into a meta itemprop / content format. What I need is the price value in the content element of the price itemprop meta:

I'm used to php but not javascript. Sorry for my lack of knowledge. Is there a way to do this? Thanks for the help.

Upvotes: 1

Views: 20

Answers (0)

Related Questions