Implementing google opt-in reviews To checkout

  • Posts: 41
  • Thank you received: 4
2 years 9 months ago #334165

-- url of the page with the problem -- : sewingmachinesuk.uk/
-- HikaShop version -- : 4.4.2
-- Joomla version -- : 3.9.27
-- PHP version -- : 7.2.34

Hi again,

I'm trying currently to implement the opt in reviews to the checkout and am having a bit on an issue.

I'm not a coder and therefore it could be anything.

I was going off of one of your previous forum topics on the same thing, however what was missing was how the code itself was placed into the view/checkout/end.php its self. I don't know anything about syntax and could use some help.

I have tried just doing it myself and have ended up breaking the end screen so that it displayed nothing. I have also tried searching a lot, but there's not a lot written on it surprisingly.

<!-- 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(
       {
         "merchant_id": 428958528,
         "order_id": "<?php echo $this->order->order_number; ?>",
         "email": "<?php echo $this->order->customer->user_email; ?>",
         "delivery_country": "<?php echo $this->order->shipping_address->address_country_code_2; ?>",
         "estimated_delivery_date": "<?php echo hikashop_getDate($this->order->order_created,'Y-m-d'); ?>",
         "opt_in_style": "CENTER_DIALOG"
       });
    });
 }
</script>
<!-- END GCR Opt-in Module Code -->

<!-- BEGIN GCR Language Code -->
<script>
 window.___gcfg = {
   lang: 'en-US'
 };
</script>
<!-- END GCR Language Code -->

This is the snippit that I have pieced together with help from the google page explaining the whole thing, and also your old form topic.
I just need to know where to paste it in basically.

I'm using the default checkout/end.php
<?php
/**
 * @package	HikaShop for Joomla!
 * @version	4.4.2
 * @author	hikashop.com
 * @copyright	(C) 2010-2021 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
if(empty($this->html)) {
	echo JText::_('THANK_YOU_FOR_PURCHASE');
	if(!empty($this->url))
		echo '<br/>'.JText::sprintf('YOU_CAN_NOW_ACCESS_YOUR_ORDER_HERE', $this->url);
} else {
	echo $this->html;
}
$this->nextButton = false;

The google help page also talks about DOCTYPE which I'm not sure if I need to worry about.

Here is the page for ref
support.google.com/merchants/answer/7106244

Any help would be amazing,
cheers

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
2 years 9 months ago #334173

Hi,

I don't see a problem with your snippet of code. It looks great !

From what I can read on your link, your code needs to be placed after the payment.
It depends on which payment method you're using. In most cases though, you'll want to place it in the "after_end"file of the checkout view, not the "end" one which is displaying the hidden redirection form to the payment gateway, before the payment is done.

Regarding where to place it:
PHP code always starts with <?php and ends with ?>
So either you could add your code right at the beginning of the view file, before the first <?php
Or if you want to add it at the end, you first need to add ?> to end the PHP code already in the view.

Also, if you have a blank page because you made a mistake in the view file, you can:
- activate the "error reporting" and "debug" settings of the Joomla configuration and access the page with the error again. You should see an error message, telling you what is wrong where.
- you can remove the customization with the corresponding button on the view files listing to go back to the default display , and possibly try again to add your code differently.

Please Log in or Create an account to join the conversation.

  • Posts: 41
  • Thank you received: 4
2 years 9 months ago #334281

Thank you!

I'll give this a go soon and let you know how it goes!

Thanks for the pointers.

Please Log in or Create an account to join the conversation.

  • Posts: 41
  • Thank you received: 4
2 years 8 months ago #334553

Hey! I Finally got around to implementing this code and am having just one error occur on the page, it just states:

"Error: delivery_country cannot be empty!"

As you an see in this screenshot.



This is the line I'm using to draw the country
"delivery_country": "<?php echo $this->order->shipping_address->address_country_code_2; ?>",

I'm just wondering if it's wrong in some way. This is just a line that I saw someone else using years ago, so it may not be relevant to my site.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
2 years 8 months ago #334557

Hi,

This would happen if you disabled the "address_country" custom field in the menu Display>Custom fields.
A sure way to get the country code would be:

<?php
$country_code = 'UK';
if(!empty($this->order->order_shipping_address_id)) {
$addressClass = hikashop_get('class.address');
$address = $addressClass->get($this->order->order_shipping_address_id);
if(!empty($address->address_country)) {
$zoneClass = hikashop_get('class.zone');
$zone = $zoneClass->get($address->address_country);
if(!empty($zone->zone_code_2)) $country_code = $zone->zone_code_2;
}
}

echo $country_code;
?>

Please Log in or Create an account to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum