You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在BigCommerce产品页结构化数据中获取单个产品评论?

BigCommerce 获取单个产品评论的方法

你目前通过Script Manager在产品页面头部添加结构化数据,只能拿到product.num_reviews(评论数量)和product.rating(聚合评分),想要获取单个评论内容,可以试试这几种方案:

1. 调用Storefront API

通过BigCommerce的Storefront API查询产品的单个评论数据,在前端用JS动态生成结构化数据。示例代码如下:

// 仅在产品页面执行
const productId = {{product.id}};
fetch(`/api/storefront/products/${productId}?include=reviews`, {
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
})
.then(response => response.json())
.then(data => {
  // 筛选出评论数据
  const reviews = data.included?.filter(item => item.type === 'review') || [];
  if (reviews.length === 0) return;

  // 找到页面上的结构化数据脚本并更新
  const schemaScript = document.querySelector('script[type="application/ld+json"]');
  if (!schemaScript) return;

  const schemaData = JSON.parse(schemaScript.textContent);
  const webPageEntry = schemaData['@graph'].find(item => item['@type'] === 'WebPage');
  
  if (webPageEntry) {
    webPageEntry.review = reviews.map(review => ({
      "@type": "Review",
      "author": { "@type": "Person", "name": review.attributes.name },
      "reviewBody": review.attributes.text,
      "rating": { "@type": "Rating", "ratingValue": review.attributes.rating },
      "datePublished": review.attributes.createdAt
    }));
    schemaScript.textContent = JSON.stringify(schemaData);
  }
});

注意:要确保你的店铺开启了Storefront API权限,并且调用次数符合平台的速率限制。

2. 自定义Stencil主题模板

如果用的是Stencil主题,可以直接修改产品模板文件(比如product.html),通过主题的自定义逻辑加载单个评论数据,注入到结构化数据中。不过官方默认模板没有直接暴露单个评论的变量,需要结合主题的评论组件或者自定义数据查询逻辑实现。

3. 借助第三方评论应用

如果店铺用了第三方评论工具(比如Yotpo、Judge.me),这类工具大多自带结构化数据支持,或者提供了可直接调用的模板变量/API,能获取单个评论内容,替换你当前Script Manager里的代码即可。

目前BigCommerce默认的模板变量确实只提供聚合评分和评论数量,想要单个评论必须通过上述几种方式实现。

内容的提问来源于stack exchange,提问作者jesus g_force Harris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 00:47:24