How to add trustpilot integration with magento 2

By | July 13, 2023
Spread the love

Trustpilot Group plc, is a Danish consumer business operating a review website founded in Denmark in 2007 which hosts reviews of businesses worldwide. Nearly 1 million new reviews are posted each month. The site offers freemium services to businesses.

You have to update magento layout files to remove magento reviews and trustpilot reviews.

  1. Create a file in custom plugin app/code/Techgroup/Addon/view/frontend/layout/catalog_product_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="reviews.tab" remove="true"/>
        
        <referenceBlock name="product.info.details">
            <block class="Magento\Catalog\Block\Product\View" name="trustpilot.tab" as="customer_reviews" template="Techgroup_Addon::trustpilot.phtml" group="detailed_info">
                <arguments>
                    <argument name="sort_order" xsi:type="string">30</argument>
                    <argument name="title" translate="true" xsi:type="string">Reviews</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>	
</page>

2. Create template file app/code/Techgroup/Addon/view/frontend/templates/trustpilot.phtml

<?php 

/**
 * @var $block Magento\Catalog\Block\Product\View
 */
$_product = $block->getProduct();
?>

<!-- TrustBox widget - Product Reviews SEO -->
<div class="trustpilot-widget" data-locale="en-US" data-template-id="xxxxxxxx" data-businessunit-id="xxxxxxxxxx" data-style-height="400px" data-style-width="100%" data-theme="light" data-sku="<?php echo $_product->getSku()?>" data-name="<?php echo $_product->getName()?>" data-review-languages="en" data-no-reviews="hide" data-fullwidth="true">
    <a href="xxxxxxxxxxxxxxxxx" target="_blank" rel="noopener">Trustpilot</a>
</div>
<!-- End TrustBox widget -->

 

Update category Page

Override summary_short.phtml in your theme folder  app/design/frontend/namespace/theme/Magento_Review/templates/helper/

Add below code in top lines

<?php
$_product = $block->getProduct();
?>
<?php if($_product):?>
    <!-- TrustBox widget - Product Mini -->
    <div class="trustpilot-widget" data-locale="en-US" data-template-id="xxxxxxxxxxxx" data-businessunit-id="xxxxxxxxx" data-style-height="24px" data-style-width="100%" data-theme="light" data-sku="<?php echo $_product->getSku()?>" data-name="<?php echo $_product->getName()?>" data-no-reviews="hide" data-scroll-to-list="true" data-style-alignment="center">
      <a href="xxxxxxxxxxxxxxxxxxx" target="_blank" rel="noopener">Trustpilot</a>
    </div>
    <!-- End TrustBox widget -->
    <?php return;?>
<?php endif;?>

Product page

Override summary.phtml in your theme folder  app/design/frontend/namespace/theme/Magento_Review/templates/helper/

<?php
$_product = $block->getProduct();
?>
<?php if($_product):?>
    <!-- TrustBox widget - Product Mini -->
    <div class="trustpilot-widget" data-locale="en-US" data-template-id="xxxxxxxxxxxx" data-businessunit-id="xxxxxxxxxxxx" data-style-height="24px" data-style-width="100%" data-theme="light" data-sku="<?php echo $_product->getSku()?>" data-name="<?php echo $_product->getName()?>" data-no-reviews="hide" data-scroll-to-list="true" data-style-alignment="center">
      <a href="xxxxxxxxxxxxxx" target="_blank" rel="noopener">Trustpilot</a>
    </div>
    <!-- End TrustBox widget -->
    <?php return;?>
<?php endif;?>