I'm trying to pull the Product ID for the product being viewed in order to pass that ID into TrustPilot's widget to display reviews for that product.
I've tried creating a Snippet with this code:
global $product;
$id = $product->get_id()
But I got an error and - I'll be honest - I don't really understand what I was doing! I've been browsing for solutions for most of the day, so I'm hoping someone might be kind enough to help!
As mentioned, the aim is to be able to populate the data-sku="xxxxxxxx" field in a TrustPilot "TrustBox" - a javascript tool that pulls & presents reviews from trustpilot. The ID will need to be updated in the HTML for the element, I think.
The whole of the TrustPilot code is shown below:
Add this to Header
<!-- TrustBox script -->
<script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js" async></script>
<!-- End TrustBox script -->
Add this to body, where you want the widget to appear
<!-- 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 -->