Created on 29 September, 2016 | Updated on 5 July, 2021
Adding Structured Data to osCommerce for Google Merchant (JSON-LD & Microdata)

Adding Structured Data to osCommerce for Google Merchant (JSON-LD)

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.

Google Structured Data Testing Result

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.

Need Help?

2 thoughts on “Adding Structured Data to osCommerce for Google Merchant (JSON-LD)”

  1. 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 ?

    1. 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.

Leave a Reply to Emmanuel Flossie Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.