Need of SKU in Open Graph and/or JSON-LD

Open to all! Ask other shopowners for help.
Post Reply
lecarlb
Contributor
Posts: 316
Joined: Mon Oct 26, 2020 5:26 pm
Phoenix Version:
Has thanked: 48 times
Been thanked: 9 times

Need of SKU in Open Graph and/or JSON-LD

Post by lecarlb »

Hello,

If adding products to Facebook and other places, they will automatically add, update or delete products if the product schema is correct. My only issue is "id" or sku.

After running a scan, Facebook can detect both Open Graph and JSON-LD. They say the only error is missing id. I looked at both header tag modules and there isn't anything indicating id or sku in the codes.

It looks less time consuming to add sku code to open graph. Is this an easy tweak? Has anyone encountered and fixed this issue?

Thank you.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4561
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 413 times

Re: Need of SKU in Open Graph and/or JSON-LD

Post by burt »

This update (coming in 1.0.8.21) will be of interest to you, as this update (which you can add into any recentish version of Phoenix, just two lines of code in two files) will allow the product schema header tag module and the opengraph header tag module to be amended via HOOK.

Of course, it does mean that a hook needs to be created but that is fairly straightforward, see next post.
User avatar
burt
Core Team
Posts: 4561
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 413 times

Re: Need of SKU in Open Graph and/or JSON-LD

Post by burt »

Example Hook, which adds in "opening hours" (eg if you had a bricks & mortar shop). Such a setting probably doesn't exist in "open graph" but this hook is meant as an example, you can set your own data as appropriate).

This hook would be saved as /includes/hooks/shop/product_info/hours.php;

Code: Select all

class hook_shop_product_info_hours {
  
  public function listen_injectHtOpenGraph($data) {
    $data['data']['product:openingHours'] = 'Mo,Tu,We,Th 09:00-12:00';
  }

  public function listen_injectHtProductSchema($schema_product) {
    $schema_product['product_schema']['openingHours'] = 'Mo,Tu,We,Th 09:00-12:00'; 
  }
  
}
Once uploaded, assuming you have turned on the header tag modules, and importantly updated them as shown in the github link above...you can "view source" and you should see the extra entries as should Facebook etc


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply