How to add structured data for Google Merchant Center to OpenCart 3, click here for OpenCart 1.5x and 2.x
Login to OpenCart
Login to your admin panel of OpenCart and navigate to Design > Theme Editor
Theme Editor
From your Choose a template, go to product > product.twig
You will now see an editor, paste the code below under {{ header }}, before you do make sure to follow the short edit instructions.
JSON LD
Make sure you change the values highlighted in capitals.
- REPLACE_WITH_CURRENCY_CODE
- REPLACE_WITH_CURRENCY_SYMBOL (twice)
Choose the code where the price decimal matches yours. (US or UK = DOT, Continental Europe = Comma)
Prices with dot decimal
<script type="application/ld+json"> { "@context": "http://schema.org/", "@type": "Product", "offers": { "@type": "Offer", "name": "{{ heading_title }}", "priceCurrency": "REPLACE_WITH_CURRENCY_CODE", {% if price %}"price": "{{ price|trim('REPLACE_WITH_CURRENCY_SYMBOL') }}", {% else %}"price": "{{ special|trim('REPLACE_WITH_CURRENCY_SYMBOL')}}",{% endif %} "itemCondition" : "http://schema.org/NewCondition", "availability" : "{{ stock }}" } } </script>
You should see the code below when you have changed the currency code and symbol.
<script type="application/ld+json"> { "@context": "http://schema.org/", "@type": "Product", "offers": { "@type": "Offer", "name": "{{ heading_title }}", "priceCurrency": "EUR", {% if price %}"price": "{{ price|trim('
Prices with comma decimal
<script type="application/ld+json"> { "@context": "http://schema.org/", "@type": "Product", "offers": { "@type": "Offer", "name": "{{ heading_title }}", "priceCurrency": "REPLACE_WITH_CURRENCY_CODE", {% if price %}"price": "{{ price|replace({'REPLACE_WITH_CURRENCY_SYMBOL': '', ',' : '.'}) }}", {% else %}"price": "{{ special|replace({'REPLACE_WITH_CURRENCY_SYMBOL': '', ',' : '.'}) }}",{% endif %} "itemCondition" : "http://schema.org/NewCondition", "availability" : "{{ stock }}" } } </script>
You should see the code below when you have changed the currency code and symbol.
<script type="application/ld+json"> { "@context": "http://schema.org/", "@type": "Product", "offers": { "@type": "Offer", "name": "{{ heading_title }}", "priceCurrency": "EUR", {% if price %}"price": "{{ price|replace({'€': '', ',' : '.'}) }}", {% else %}"price": "{{ special|replace({'€': '', ',' : '.'}) }}",{% endif %} "itemCondition" : "http://schema.org/NewCondition", "availability" : "{{ stock }}" } } </script>
HTML
Make sure you change the values highlighted in capitals.
- REPLACE_WITH_CURRENCY_CODE
- REPLACE_WITH_CURRENCY_SYMBOL (twice)
Choose the code where the price decimal matches yours. (US = DOT, Continental Europe = Comma)
Prices with dot decimal
<div itemscope itemtype="http://schema.org/Product"> <meta itemprop="name" content="{{ heading_title }}" /> <div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer"> <meta itemprop="priceCurrency" content="REPLACE_WITH_CURRENCY_CODE"> {% if price %} <meta itemprop="price" content="{{ price|trim('REPLACE_WITH_CURRENCY_SYMBOL') }}"> {% else %} <meta itemprop="price" content="{{ special|trim('REPLACE_WITH_CURRENCY_SYMBOL') }}"> {% endif %} <meta itemprop="availability" content="{{ stock }}"> <meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition" /> </div> </div>
If your in the US, your code should look like the example below.
<div itemscope itemtype="http://schema.org/Product"> <meta itemprop="name" content="{{ heading_title }}" /> <div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer"> <meta itemprop="priceCurrency" content="USD"> {% if price %} <meta itemprop="price" content="{{ price|trim('
Prices with comma decimal
<div itemscope itemtype="http://schema.org/Product"> <meta itemprop="name" content="{{ heading_title }}" /> <div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer"> <meta itemprop="priceCurrency" content="REPLACE_WITH_CURRENCY_CODE"> {% if price %} <meta itemprop="price" content="{{ price|replace({'REPLACE_WITH_CURRENCY_SYMBOL': '', ',' : '.'}) }}"> {% else %} <meta itemprop="price" content="{{ special|replace({'REPLACE_WITH_CURRENCY_SYMBOL': '', ',' : '.'}) }}"> {% endif %} <meta itemprop="availability" content="{{ stock }}"> <meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition" /> </div> </div>
If your in Europe, your code should look like the example below.
<div itemscope itemtype="http://schema.org/Product"> <meta itemprop="name" content="{{ heading_title }}" /> <div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer"> <meta itemprop="priceCurrency" content="REPLACE_WITH_CURRENCY_CODE"> {% if price %} <meta itemprop="price" content="{{ price|replace({'€': '', ',' : '.'}) }}"> {% else %} <meta itemprop="price" content="{{ special|replace({'€': '', ',' : '.'}) }}"> {% endif %} <meta itemprop="availability" content="{{ stock }}"> <meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition" /> </div> </div>
You should see something like the image below
Now save and check the landing page for any errors.
Testing the results
Verify that you have done it correctly by checking the page with Google’s Structured Data Testing Tool
Please note the data testing tool, only checks for syntax errors, not for policy checks. However, if you add the code as is, then you are withing Google Shopping policy requirements.
ThanK You!!!
I added the HTML to my product.twig under {{ header }}, but I’m unable to verify using the Google Structured Data Testing Tool. Any suggestions? https://uploads.disquscdn.c…
Hello Mason, I have already emailed you.
“availability” : “{{ stock }}” give error in Google structured data test, have to change it to “availability” : “http://schema.org/InStock”. Same for “name”: “{{ heading_title }}”, How to fix that? you can run a test on https://mitrecyclers.com/alcatel-pixi-4-9001x-8gb-unlocked-grade-ab
I have replied to your email.
Availability is translated and become mistaken, no review.
You will need some custom coding in this case. If you need help, please contact me [email protected]
Hi,Using JSON-LD OC 3 & after running through the testing tool I get : A value for the name field is required.Any suggestions/help appreciated.Regards.Dab
Hello Jonathan, the tutorial has been updated with the name field attribute. Hope this helps.
Living in the Netherlands we use a decimal comma instead of a decimal point. A comma is not allowed in microdata so I made a small change to the code to get no errors and to replace the euro symbol and the comma:
It works great now. Thanks for posting the code!
Hi Aiko, that’s exactly right, thank you for posting your code, I will soon update the article to cover both continental Europe and US. Thanks!
Nice updated Article. Shouldn’t the article be based on JSON-LD for OpenCart 3?
If you want to use JSON-LD you can, at the time of writing I have not yet changed this. Currently you can use both HTML or JSON_LD
Hello, I have updated the article both include JSON LD and HTML, so you can choose whichever you want to include. Hope it helps.