Google Seller Rating Integration to One Page Checkout
Hello everyone,
I am looking for into integrating Google Seller Rating to my site.
It is using ZC 1.5.7 with latest OPC and Boostrap templates.
As per google,i need to addthefollowing code to my order confirmation page:
Code:
<!-- BEGIN GCR Opt-in Module Code -->
<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(
{
// REQUIRED
"merchant_id": "MERCHANT_ID",
"order_id": "ORDER_ID",
"email": "CUSTOMER_EMAIL",
"delivery_country": "COUNTRY_CODE",
"estimated_delivery_date": "YYYY-MM-DD",
// OPTIONAL
"products":[{"gtin":"GTIN1"}, {"gtin":"GTIN2">}],
"opt_in_style": "OPT_IN_STYLE"
});
});
}
</script>
<!-- END GCR Opt-in Module Code -->
However, I am not sure /confused at to which files I am supposed to add it and where in the file.
Anyone ever successfully integrated Seller Rating to their site?
Any help would be appreciated.
Thank you
Re: Google Seller Rating Integration to One Page Checkout
Your best approach is to create a file (say jscript_gsr_optin.php) in /includes/modules/pages/checkout_success. That newly-added file should look similar to
Code:
<?php
if (empty($order_summary)) {
return;
}
?>
<!-- BEGIN GCR Opt-in Module Code -->
<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(
{
// REQUIRED
"merchant_id": "MERCHANT_ID", //- Your Merchant ID value
"order_id": "<?php echo $order->info['order_id']; ?>",
"email": "<?php echo $order->customer['email_address']; ?>",
"delivery_country": "<?php echo (!empty($order->delivery['country']['iso_code_2']) ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2']; ?>",
"estimated_delivery_date": "YYYY-MM-DD", //- The purchase date/time is present in $order->info['date_purchased']
Re: Google Seller Rating Integration to One Page Checkout
Quote:
Originally Posted by
lat9
Your best approach is to create a file (say jscript_gsr_optin.php) in /includes/modules/pages/checkout_success. That newly-added file should look similar to
Code:
<?php
if (empty($order_summary)) {
return;
}
?>
<!-- BEGIN GCR Opt-in Module Code -->
<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(
{
// REQUIRED
"merchant_id": "MERCHANT_ID", //- Your Merchant ID value
"order_id": "<?php echo $order->info['order_id']; ?>",
"email": "<?php echo $order->customer['email_address']; ?>",
"delivery_country": "<?php echo (!empty($order->delivery['country']['iso_code_2']) ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2']; ?>",
"estimated_delivery_date": "YYYY-MM-DD", //- The purchase date/time is present in $order->info['date_purchased']
Thank you lat9 for the reply. I really appreciate the help and guidance on this.
I created the file named jscript_gsr_optin.php in uploaded it to includes/modules/pages/checkout_success.
i have the following code in the file:
Code:
<!-- BEGIN GCR Opt-in Module Code -->
<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(
{
// REQUIRED
"merchant_id": "9****3", //- Your Merchant ID value
"order_id": "<?php echo $order->info['order_id']; ?>",
"email": "<?php echo $order->customer['email_address']; ?>",
"delivery_country": "<?php echo (!empty($order->delivery['country']['iso_code_2']) ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2']; ?>",
"estimated_delivery_date": "YYYY-MM-DD", //- The purchase date/time is present in $order->info['date_purchased']
// OPTIONAL
"products":[{"gtin":"GTIN1"}, {"gtin":"GTIN2">}],
"opt_in_style": "OPT_IN_STYLE"
});
});
}
</script>
<!-- END GCR Opt-in Module Code -->
However, when i attempt to checkout , i am getting a blank page for /index.php?main_page=checkout_success and the following error is logged in:
Code:
[16-Jan-2023 19:10:35 America/Los_Angeles] PHP Parse error: syntax error, unexpected ';' in D:\xampp\htdocs\royal-fleur\includes\modules\pages\checkout_success\jscript_gsr_optin.php on line 27
[16-Jan-2023 19:10:35 America/Los_Angeles] Request URI: /royal-fleur/index.php?main_page=checkout_success, IP address: ::1
--> PHP Parse error: syntax error, unexpected ';' in D:\xampp\htdocs\royal-fleur\includes\modules\pages\checkout_success\jscript_gsr_optin.php on line 27.
Any help on fixing this please?
Thank you again for your assistance
Re: Google Seller Rating Integration to One Page Checkout
Change line 27 to
Code:
"delivery_country": "<?php echo (!empty($order->delivery['country']['iso_code_2']) ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2']); ?>",
Re: Google Seller Rating Integration to One Page Checkout
Quote:
Originally Posted by
swguy
Change line 27 to
Code:
"delivery_country": "<?php echo (!empty($order->delivery['country']['iso_code_2']) ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2']); ?>",
Thank you swguy,
I made the changes to line 27 but i am still getting another error.
The error is :
Code:
[17-Jan-2023 19:32:00 America/Los_Angeles] Request URI: /royal-fleur/index.php?main_page=checkout_success, IP address: ::1
#1 require(D:\xampp\htdocs\royal-fleur\includes\modules\pages\checkout_success\jscript_gsr_optin.php) called at [D:\xampp\htdocs\royal-fleur\includes\templates\bootstrap\common\html_header.php:201]
#2 require(D:\xampp\htdocs\royal-fleur\includes\templates\bootstrap\common\html_header.php) called at [D:\xampp\htdocs\royal-fleur\index.php:43]
--> PHP Warning: Illegal string offset 'iso_code_2' in D:\xampp\htdocs\royal-fleur\includes\modules\pages\checkout_success\jscript_gsr_optin.php on line 27.
The Checkout process goes thru and i am getting the order confirmation page.
However, I am not getting any popup from Google regarding the opt-in survey or anything. Is this normal? Any experience with it?
Thank you for your help
Re: Google Seller Rating Integration to One Page Checkout
I got it to "work" somehow by doing this to fix my error since we only ship to the US anyway.
Code:
"delivery_country": "US",
I am having issue with the delivery date though.
I got the plugin to work specifying today date ( i.e. "estimated_delivery_date": "2023-01-18")
what do i need to do so the date rendered is the purchase date?
Thank you for your help
Re: Google Seller Rating Integration to One Page Checkout
Quote:
Originally Posted by
nicksab
I got the plugin to work specifying today date ( i.e. "estimated_delivery_date": "2023-01-18")
what do i need to do so the date rendered is the purchase date?
Thank you for your help
Are you sure you want the delivery date to be the same as purchase date? Isn't there any lead time or shipping time?
If you want it to be the same as purchase date:
Code:
"estimated_delivery_date": "<?php echo date('Y-m-d',strtotime($order->info['date_purchased'])); ?>",
If you want to add some time:
Code:
"estimated_delivery_date": "<?php echo date('Y-m-d',strtotime("+1 day", $order->info['date_purchased'])); ?>",
Change the number in red to whatever you need.
Re: Google Seller Rating Integration to One Page Checkout
Quote:
Originally Posted by
balihr
Are you sure you want the delivery date to be the same as purchase date? Isn't there any lead time or shipping time?
If you want it to be the same as purchase date:
Code:
"estimated_delivery_date": "<?php echo date('Y-m-d',strtotime($order->info['date_purchased'])); ?>",
If you want to add some time:
Code:
"estimated_delivery_date": "<?php echo date('Y-m-d',strtotime("+1 day", $order->info['date_purchased'])); ?>",
Change the number in red to whatever you need.
Thank you balihr.
That s definitely a great point. We do offer same day delivery but obviously this date can vary greatly.
Customer can pick the delivery date via a datepicker in product attribute. The site is at royal-fleurdotcom if needed.
Looks like option #2 would be a perfect fit however I am getting an error in developer console.
error is as follow "Error: Invalid estimated_delivery_date. Make sure the date format is YYYY-MM-DD" and no pop up from google survey.
I tried option #1 as an alternative and it worked without any issue.
I would prefer #2 if possible but it seems google api doesn't like the"+1 day" part.
Any suggestions?
Thank you for your help
Re: Google Seller Rating Integration to One Page Checkout
Quote:
Originally Posted by
nicksab
I would prefer #2 if possible but it seems google api doesn't like the"+1 day" part.
Any suggestions?
Sorry, blonde moment... The code should be:
Code:
"estimated_delivery_date": "<?php echo date('Y-m-d',strtotime("+1 day", strtotime($order->info['date_purchased']))); ?>",
Re: Google Seller Rating Integration to One Page Checkout
Quote:
Originally Posted by
balihr
Sorry, blonde moment... The code should be:
Code:
"estimated_delivery_date": "<?php echo date('Y-m-d',strtotime("+1 day", strtotime($order->info['date_purchased']))); ?>",
Thank you very much balihr. It worked like charm