Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicomollet/0fdb6941ec17ded0b94d76ab7fc7b7f4 to your computer and use it in GitHub Desktop.
Save nicomollet/0fdb6941ec17ded0b94d76ab7fc7b7f4 to your computer and use it in GitHub Desktop.
WooCommerce: Adds Brand attribute to "Product" Structured Data
<?php
/**
* WooCommerce: Adds Brand attribute to "Product" Structured Data
*
* @param array $data
*
* @return array
*/
function woocommerce_structured_data_product_brand ($data) {
global $product;
$data['brand'] = 'Custom Brand' ?? null;
return $data;
}
add_filter( 'woocommerce_structured_data_product', 'woocommerce_structured_data_product_brand' );
@stephdigiovanni
Copy link

J'ai modifié ta ligne "$data['brand'] = 'Custom Brand' ?? null;" par "$data['brand'] = $product->get_attribute('pa_marque') ?? null;" et sur Facebook je n'ai toujours pas la marque des produits...

@nicomollet
Copy link
Author

@stephdigiovanni faudrait savoir quelle donnée est récupérée par ce plugin, en toute logique ça devrait être Brand :(

@stephdigiovanni
Copy link

J'ai recupéré leur modèle de données en CSV et c'est bien "brand" qui est attendu.

@nicomollet
Copy link
Author

Après il y a peut-être un cache.

Ce filtre ne fait que modifier le schema (rich text) en ajoutant brand.
Si le plugin ne se base pas dessus, ça ne va pas marcher.

Faudrait vérifier comment sont transmis les produits à Facebook, tu sais ?

@stephdigiovanni
Copy link

J'ai du cache (litespeed) sur le serveur mais je l'ai vidé.
Je pense que FB utilise un fichier au format JSON/LD

@stephdigiovanni
Copy link

J'ai fait un echo $data['brand'] et ça renvoie bien la marque. Donc soit c'ets un pb de cache soit le filter marche pas. Non ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment