I saw the microdata markup on this thread: https://www.pricetapestry.com/node/4642, however, I don't need ratings/review and the code referred to doesn't exist in 15/09A. I have image caching enabled for product pages, in case any code needs to be placed there. How can I markup?
Alternative modification with each individual merchant offer marked up for price comparison;
Edit products.php and look for the following code beginning at line 160:
if (isset($product)) require("html/product.php");
if (isset($prices)) require("html/prices.php");
...and REPLACE with:
print "<div itemscope itemtype='http://schema.org/Product'>";
if (isset($product)) require("html/product.php");
if (isset($prices)) require("html/prices.php");
print "</div>";
Edit html/product.php and first locate the the opening img tag within line 32:
<img alt='...
...and insert the item property before the alt attribute e.g.
<img itemprop='image' alt='...
And then look for the following code at line 40:
<h1><?php print $product_main["name"]; ?></h1>
...and REPLACE with:
<h1 itemprop='name'><?php print $product_main["name"]; ?></h1>
And then the following code at line 44:
<p><?php print $product_main["description"]; ?></p>
...and REPLACE with:
<p itemprop='description'><?php print $product_main["description"]; ?></p>
Edit html/prices.php and look for the following code at line 59:
<td class='pt_pr_price'><?php print tapestry_price($product["price"]); ?></td>
...and REPLACE with:
<td class='pt_pr_price'>
<span itemprop='offers' itemscope itemtype='http://schema.org/Offer'>
<span itemprop='priceCurrency' content='CURRENCY_CODE' />
<span itemprop='price' content='<?php print $product["price"]; ?>'><?php print tapestry_price($product["price"]); ?></span>
</span>
</td>
(replace CURRENCY_CODE in the above with the 3-letter currency code appropriate for your installation e.g. GBP, EUR, USD etc.)
Cheers,
David.
--
PriceTapestry.com
David,
Figured out how to markup so there's no error. In html > product.php
<span itemprop='offers' itemscope itemtype='http://schema.org/Offer'>
<span itemprop="priceCurrency" content="USD">$</span>
<span itemprop='price'><?php print tapestry_price2($product_main["price"]); ?></span>
<b><?php print translate("Sale Price:"); ?></b>
<b>
<?php
if ($product_main["sale_price"] && ($product_main["sale_price"] != "0.00"))
{
print tapestry_price($product_main["sale_price"]);
}
?>
</b>
</span>
<br><div class='br'>
<span><?php print translate("Buy:"); ?></span>
{code saved}
My question now: Is there any way to automatically substitute the Sale Price if available? The schema.org validFrom / validThrough isn't a viable option.
Hi,
I've updated the above to include the priceCurrency span and also the price as the content attribute of the price span - the example at http://schema.org/Offer indicates that the currency symbol as part of the price span is acceptable as long as the content attribute is in place so it shouldn't be necessary to use a new tapestry_price() function but if you're still having validation errors let me know and I'll check that out further.
Regarding sale price if present and not 0.00, where you now have:
<?php print tapestry_price2($product_main["price"]); ?>
(using your new tapestry_price2() function)
...REPLACE with:
<?php
$price = ($product_main["sale_price"] && ($product_main["sale_price"]!="0.00")?$product_main["sale_price"]:$product_main["price"]);
print tapestry_price2($price);
?>
Cheers,
David.
--
PriceTapestry.com
Hi David,
The replacement code for the sale price makes both reg & sale prices the same on the product page.
To hopefully explain better: I want to automatically substitute an available sale price in the structured data, but not on the product page, which should still display separate regular and sale price (if available). Is this possible?
Hi,
As you've a few changes in place please could you email me the modified html/product.php and I'll check that out for you...
Thanks,
David.
--
PriceTapestry.com
Hi David,
been trying to follow this to implement into the WP PTO version, but struggling with parts.
Do you happen to have a copy of the PTO template & PTO file mods to add all parts of the structured data schema to PTO?
Regards,
Graham
Hi Graham,
I don't unfortunately but if you could let me know which parts you are struggling with, your existing template markup and how you would like to change it to include the microdata I'll certainly try and point you in the right direction...
Cheers,
David.
--
PriceTapestry.com
Hi David,
thanks for your response.
I've managed to incorporate most of the changes into PTO template but not sure where to start with the last part:
"And finally the following code at line 71:
<?php
print $product_bestPriceMerchants;
?>
<?php
print $product_bestPriceMerchants;
?>
<?php
$offerCount = count($product["products"]);
if ($offerCount>1)
{
print "<span itemprop='offers' itemscope itemtype='https://schema.org/AggregateOffer'>";
print "<span itemprop='lowPrice'>".$config_currencyHTML.$product["products"][0]["price"]."</span>";
print "<span itemprop='highPrice'>".$config_currencyHTML.$product["products"][$offerCount-1]["price"]."</span>";
print "<span itemprop='offerCount'>".$offerCount."</span>";
print "</span>";
}
?>
Any help appreciated.
Hi Graham,
To do the equivalent in the plugin, edit pto_product.php and look for the following code at line 505:
$html_product = str_replace("%PRICE_LINKS%",implode(", ",$price_links),$html_product);
...and REPLACE with:
$html_price_links = implode(", ",$price_links);
if ($numRows>1)
{
$html_price_links .= "<span itemprop='offers' itemscope itemtype='https://schema.org/AggregateOffer'>";
$html_price_links .= "<span itemprop='lowPrice'>".$pto_config_currencyHTML.$pto_productResults[0]->price."</span>";
$html_price_links .= "<span itemprop='highPrice'>".$pto_config_currencyHTML.$pto_productResults[($numRows-1)]->price."</span>";
$html_price_links .= "<span itemprop='offerCount'>".$numRows."</span>";
$html_price_links .= "</span>";
}
$html_product = str_replace("%PRICE_LINKS%",$html_price_links,$html_product);
Cheers,
David.
--
PriceTapestry.com
Hi David,
as opposed to microdata, would it be a better idea to add this data using JSON and one of the many available WP plugin's ?
Have already tried, but don't know how to call up the required data to populate the neccessary fields. What variables to use, custom field names etc. If it's even possible with the data being stored outside of the WP database tables.
What do you advise?
Hi Graham,
As the data isn't part of the WP database schema itself there wouldn't not be any microdata plugins that would "just work".
Cheers,
David.
--
PriceTapestry.com
Hi,
For schemas;
http://schema.org/Product
http://schema.org/Offer
http://schema.org/AggregateOffer
Edit html/product.php and look for the following code at line 40:
<div class='row pt_p'>
...and REPLACE with:
<div class='row pt_p' itemscope itemtype='http://schema.org/Product'>
Then locate the the opening img tag within line 46:
<img alt='...
...and insert the item property before the alt attribute e.g.
<img itemprop='image' alt='...
And then look for the following code at line 54:
<h1><?php print $product_main["name"]; ?></h1>
...and REPLACE with:
<h1 itemprop='name'><?php print $product_main["name"]; ?></h1>
And then the following code at line 48:
<p><?php print $product_main["description"]; ?></p>
...and REPLACE with:
<p itemprop='description'><?php print $product_main["description"]; ?></p>
And finally the following code at line 66:
<?php print tapestry_price($product_main["price"]); ?> <?php print translate("from"); ?>
...and REPLACE with:
<span itemprop='offers' itemscope itemtype='http://schema.org/Offer'>
<span itemprop='priceCurrency' content='CURRENCY_CODE' />
<span itemprop='price' content='<?php print $product_main["price"]; ?>'><?php print tapestry_price($product_main["price"]); ?></span> <?php print translate("from"); ?>
</span>
(replace CURRENCY_CODE in the above with the 3-letter currency code appropriate for your installation e.g. GBP, EUR, USD etc.)
And finally the following code at line 71:
<?php print $product_bestPriceMerchants; ?>
...and REPLACE with:
<?php print $product_bestPriceMerchants; ?>
<?php
$offerCount = count($product["products"]);
if ($offerCount>1)
{
print "<span itemprop='offers' itemscope itemtype='https://schema.org/AggregateOffer'>";
print "<span itemprop='lowPrice'>".$config_currencyHTML.$product["products"][0]["price"]."</span>";
print "<span itemprop='highPrice'>".$config_currencyHTML.$product["products"][$offerCount-1]["price"]."</span>";
print "<span itemprop='offerCount'>".$offerCount."</span>";
print "</span>";
}
?>
I'll post an alternative modification below in just a moment spanning both the product and price comparison table with each merchant result marked up as an offer...
Cheers,
David.
--
PriceTapestry.com