【发布时间】:2021-05-31 08:19:52
【问题描述】:
我正在尝试提取正在查看的产品的产品 ID,以便将该 ID 传递到 TrustPilot 的小部件以显示对该产品的评论。
我尝试使用以下代码创建片段:
global $product;
$id = $product->get_id()
但是我遇到了一个错误 - 老实说 - 我真的不明白我在做什么!一天中的大部分时间我都在寻找解决方案,所以我希望有人能提供帮助!
如前所述,目的是能够在 TrustPilot“TrustBox”中填充 data-sku="xxxxxxxx" 字段 - 一种从 trustpilot 提取和呈现评论的 JavaScript 工具。我认为需要在元素的 HTML 中更新 ID。
整个 TrustPilot 代码如下所示:
将此添加到页眉
<!-- TrustBox script -->
<script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js" async></script>
<!-- End TrustBox script -->
将此添加到正文中,您希望小部件出现的位置
<!-- TrustBox widget - Product Reviews SEO -->
<div class="trustpilot-widget" data-locale="en-GB" data-template-id="5717796816f630043868e2e8" data-businessunit-id="5d472f87ff988700011c73b8" data-style-height="700px" data-style-width="100%" data-theme="light" data-sku="487" data-name="10 Plantshake Pack" data-review-languages="en">
<a href="https://uk.trustpilot.com/review/foga.co" target="_blank" rel="noopener">Trustpilot</a>
</div>
<!-- End TrustBox widget -->
【问题讨论】:
标签: php wordpress woocommerce product hook-woocommerce