Google Customer Reviews and Woocommerce

Google Customer Reviews are available for selected countries now, including The Netherlands and Belgium. At the moment i’m not sure if this service should replace or extend other review services like Trustpilot and The Feedback Company.

To use the Google Customer Review service a is Google Merchant account is required.

To use this service you’ll have to add some JavaScript code to the order confirmation page of your webshop. For Woocommerce you can easily use the woocommerce_thankyou hook to add the JavaScript code. To get the required information of the order you can create a new instance of the WC_Order class inside your custom function of the hook as follows:

$order = new WC_Order( $order_id );

The WC_Order class inherit properties from WC_Abstract_Order which provide you the required information about the customer. Properties for both the customer’s e-mail address and shipping address are available.

The final code for the hook may look like that shown beneath. You can add this code in the functions.php file in your theme directory:

add_action( ‘woocommerce_thankyou’, ‘my_google_reviews’ );
function my_google_reviews( $order_id ) {

// Lets grab the order
$order = new WC_Order( $order_id );
?>
<script src=”https://apis.google.com/js/platform.js?onload=renderOptIn” async defer></script>

<script>
window.renderOptIn = function() {
window.gapi.load(‘surveyoptin’, function() {
window.gapi.surveyoptin.render(
{
“merchant_id”: 11111111,
“order_id”: “<?php echo $order_id; ?>”,
“email”: “<?php echo $order->billing_email; ?>”,
“delivery_country”: “<?php echo $order->shipping_country; ?>”,
“estimated_delivery_date”: “<?php echo my_delivery_date(); ?>”
});
});
}
</script>
<?php
}

As you can see in the above the estimated delivery date value is dynamically set by an other custom function. My custom my_delivery_date() look like that shown below:

function my_delivery_date($send_day = 1) {

if (date(‘N’) === “5” && date(“G”) >= 16) { //vrijdag
$send_day += 3;
}
elseif (date(‘N’) === “6”) { //zaterdag
$send_day += 2;
}
elseif (date(‘N’) === “7”) { //zondag
$send_day += 1;
}
elseif ( date(“G”) >= 16) {
$send_day += 1;
}
return date(‘Y-m-d’,time()+24*60*60*$send_day);
}

The above function is used for my webshops at Webvrouw.nl and Menstruatiecups.nl. For Menstrualcups.eu which has many international orders i can used the same code, after setting $send_day to for instance 3 days.

You can also use the following JavaScript code to set the language of the service.

<!– BEGIN GCR Language Code –>
<script>
window.___gcfg = {
lang: ‘nl’
};
</script>
<!– END GCR Language Code –>

Because of the same code is used to set the language of the badge, i’ve add the language code only to the footer.php file of my theme. The footer.php file also contains the JavaScript code for the Badge. The badge will look like that shown in the figure below:

Badge Google review service

Save

5 Responses to “Google Customer Reviews and Woocommerce”

  1. Peter

    I have a doubt, I just need to put the final code on the functions.php of my theme (Avada) or I need to put something else to other files?
    Thanks! great job!

    Reply
  2. Peter

    I have put the final code in the functions.php of my child theme of Avada,
    only changing the “merchant_id” for the id that Merchant Center gives me
    and It does not seem to work.
    Do you have any idea? Maybe I have to put “” in some place as the Merchant Center says?
    Thanks a lot for your help!

    Reply
  3. Christian

    Hi,
    I had to replace
    return date(‘Y-m-d’,time()+24*60*60*$send_day);
    with
    return date(“Y-m-d”,time()+24*60*60*$send_day);
    to have it work.
    Thanks a lot for this article.

    Reply

Leave a Reply

(will not be published)