-1

In my ProductDetails.html page I have added the below mircodata, but I need to toggle it on and off based on inventory being InStock or OutofStock. Right now it is toggled InStock for all products. Please help!

<link itemprop="availability" href="schema.org/InStock"; />
Wes Foster
  • 8,770
  • 5
  • 42
  • 62
Vbe
  • 1
  • 1
  • 2

1 Answers1

0

Just change this to OutOfStock when the product is out of stock http://schema.org/OutOfStock, use -

<link itemprop="availability" href="http://schema.org/OutOfStock" />

and remove the InStock line. Whatever code you use to display the number in stock or an in stock/out of stock message can be used for this. Using json-ld for controlling the in stock/out of stock status can be done by using some code (javascript for example) to write a script that dynamically writes the JSON-LD.

If you want a very, very simple solution you could use a different, slightly ambiguious term instead of In Stock/Out of Stock, these are listed on http://schema.org/ItemAvailability as PreOrder, LimitedAvailability, InStoreOnly, Online Only. Not every bit of information is needed for your structured data to work. None are optional, although google does give an error if some things are missing it will recognize (and use) the remainder of the data.

Mousey
  • 1,855
  • 19
  • 34