Injecting Buy button attribute values using Javascript <- Fails validation

Hi there,
I am injecting attribute values in to the button. as such
"$(’.snipcart-add-item’).attr( ‘data-item-price’,sdprice);
$(’.snipcart-add-item’).attr( ‘data-item-id’,sdproduct); " … etc

Why ? because i want to maintain all product prices and description in one page easier to manage etc etc

Everything works as expected. until I hit the validation when checking out. obviously scraping the data-url doesn’t provide the necessary information… any thoughts or ideas would be much appreciated?

I guess your scraper doesn’t execute JS… may have to revert to server side code… but I will wait for some one from support to validate. please !

Hi @RonSingh, that is correct, we only fetch the page HTML and check the contents in it, we do not run JS before looking for the data attributes.

If you fetch that data from an API, you can use our JSON crawler to get the data from the API too.

Thanks.

Thank @nelitow for your quick response.
So will this solution work
data-item-url. = “product.php?productID=xyz”

product.php returns
Content-Type application/json
and JSON like

{
  "id": "20",
  "price": 50.00,
  "url": "https://snipcart.com/products/1.json"
}

This is using your JSON crawler .

Please let me know if this would work. Much appreciated !

Hi @RonSingh
Yes, something like this should work just fine.

1 Like