How to replace Schema «availability» string with multiple values?

144 Views Asked by At

I am noob with structured data implementation and don't have any code knowledge. I have been looking for a week how to solve my problem with "availability" in Google structured data testing tool.

My stocks on the front have 3 possibilities :

  • "Stock : 1234" (text + stock numbers)
  • "Stock : Coming soon"
  • "Stock : On demand"

Google Results example

But he problem is Goggle accept only in my case "InStock" or "OutOfStock"

I have a CSS variable element #PdtXQStock named in a variable "Product-stock"

How can have :

if "availability" string contain numbers (not is number) ==> output "InStock"

if "availability" string is "Stock : Coming soon" ==> output "OutOfStock"

if "availability" string is "Stock : On demand" ==> output "InStock"

What is the proper Custom Js function from beginning to end?


function(){
var string = {{Product-stock}};
string = "https://schema.org/InStock";
string = string.replace(/Stock : Coming Soon/g, "OutOfStock");
string = string.replace(/Stock : On demand/g, "InStock");
return string.replace;
}
0

There are 0 best solutions below