In this article, I explain how to add structured data for Google Merchant using JSON-LD easily.
Open & edit the correct file
Open up your FTP or IDE and source the file in the following location in the root of your directory you will find a file named product_info.php
Before you start editing the file, please copy it and rename it to something else, for example : products_info.backup.php
Open the original file and scroll to the bottom of the page.
You will see an opening <?php tag, and underneath it two includes the template_bottom and application_bottom files.
Before the opening <?php tag, place the below code.
<script type="application/ld+json"> { "@context": "http://schema.org/", "@type": "Product", "offers": { "@type": "Offer", "priceCurrency": "<?php echo tep_output_string($currency); ?>", "price": "<?php echo preg_replace('/[^0-9.]+/','',preg_replace('/,/','.',$products_price)); ?>", "itemCondition" : "http://schema.org/NewCondition", "availability" : "<?php if ($product_info['products_quantity'] >= 1){echo 'In Stock';}else{echo 'Out of Stock';} ?>" } } </script>
If you have done it correctly, you should see something similar to the image below.
Save the file
Checking The Results
You can use Google’s Structured data testing tool, to check if everything is done correctly. The below image shows an example of a correct listing.
Copy your landing page link (address bar URL) and paste it in the field for fetching the URL.
When you have warnings in your diagnostics tab, remember that it takes up to 30 days before they will disappear, this is because Google does not crawl your landing pages every day but sporadically during 30 days.
tried to incorporate your code on my STS templated version of Oscommerce so i added the JSON variant to the top of my product_info.tpl.php file before the code but googles structured data checker came back with errors as follows:-
Product2 ERRORS0 [email protected]
@typeOfferpriceCurrencyGBPitemConditionhttp://schema.org/NewConditionavailabilityIn StockcancelOne of price or priceSpecification must be provided.cancel
nameA value for the name field is required.
I wanted to show product ratings as star ratings on my listings, whether the item was in stock, and price fields etc. How would I do this ?
You need to add the code to the bottom of the page above template bottom and application bottom. Not at the top of the page.
This is only a Google Merchant related article and does not cover markup which is not supported, such as product ratings. I recommend you ask on a OsCommerce community forum.