Hi all, Not sure if anyone has tried this, but I am currently working on integrating 'Google Customer review's opt-in' in my virtuemart site.
So far I have created a custom html module with the Google review opt-in code and have got the module loading in the 'order_done.php' template. I have assigned this module on a hidden page.
Now I am at the point where I have the badge and the survey loading in the correct areas, but it is not inserting the user email field in the specified position. So the e-mail address for google to send the e-mail to, comes up as email.
Also if someone has an idea of adding an automated, estimated shipping date, for instance, current date +2 days.
Here is the code that I used:
Google 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":"MY-MERCHANT-ID-CODE",
"order_id": "virtuemart_orders",
"email": "email", ( this field needs to echo the virtuemart user email address )
"delivery_country": "SA",
"estimated_delivery_date": "2017-07-27", ( this field needs to add the order date and if possible add 2 days for instance )
// OPTIONAL
"opt_in_style": "OPT_IN_STYLE"
});
});
}
</script>
<!-- END GCR Opt-in Module Code -->
<<<<<<_________________Google code end_________________>>>>>>
Virtuemart confirmation page
<?php
defined('_JEXEC') or die('');
/**
*
* Template for the shopping cart
*
* @package VirtueMart
* @subpackage Cart
* @author Max Milbers
*
* @link ${PHING.VM.MAINTAINERURL}
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
echo '<div class="vm-wrap vm-order-done">';
$modules = JModuleHelper::getModules('googlereview'); ( code to assign my custom html module on the success page )
foreach($modules as $mod)
{
echo JModuleHelper::renderModule($mod);
}
if (vRequest::getBool('display_title',true)) {
echo '<h3>'.vmText::_('COM_VIRTUEMART_CART_ORDERDONE_THANK_YOU').'</h3>';
}
$this->html = vRequest::get('html', vmText::_('COM_VIRTUEMART_ORDER_PROCESSED') );
echo $this->html;
if (vRequest::getBool('display_loginform',true)) {
$cuser = JFactory::getUser();
if (!$cuser->guest) echo shopFunctionsF::getLoginForm();
}
echo '</div>';
If anyone could please help me out with the code for the email field and the date to work properly, that would be great :)
For anyone looking for this date function for Google Customer Review opt in:
<?php echo date("Y-m-d", strtotime(date() . " + 1 day")); ?>
This is working for me.
Now all that's left for the Google Review opt-in to work with virtuemart is the e-mail address field.
It works if I input my own e-mail address in the field, but that's quite worthless, so if anyone knows to call the current user e-mail address?
Something like: <?php echo $email ?>
but that doesn't work
Here's the complete code to add at the bottom of your /public_html/components/com_virtuemart/views/cart/tmpl/order_done.php
Nevermind about the module. All you need is this code, and replace the Merchant id with your own:
?>
<!-- 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": GOOGLE-MERCHANT-ID,
"order_id": "Webits Order",
"email": "<?php echo $_POST["email"]; ?>",
"delivery_country": "SA",
"estimated_delivery_date": "<?php echo date("Y-m-d", strtotime(date() . " + 1 day")); ?>",
"opt_in_style": "OPT_IN_STYLE"
});
});
}
</script>
<!-- END GCR Opt-in Module Code -->
<!-- BEGIN GCR Language Code -->
<script>
window.___gcfg = {
lang: 'en_US'
};
</script>
<!-- END GCR Language Code -->
Happy Google reviews!
HI Creepzn,
I followed your instructions but the opt-in window did not activate
I noticed that the code appears on the order confirm page but the id order and email fields remain empty.
Where am I wrong?
Regards
Klaus
<script>
window.renderOptIn = function() {
window.gapi.load('surveyoptin', function() {
window.gapi.surveyoptin.render(
{
// REQUIRED FIELDS
"merchant_id": 120297787,
"order_id": "",
"email": "",
"delivery_country": "IT",
"estimated_delivery_date": "2018-02-03",
// OPTIONAL FIELDS
"opt_in_style": "CENTER_DIALOG"
});
});
}
</script>
<!-- BEGIN GCR Language Code -->
<script>
window.___gcfg = {
lang: 'it'
};
</script>
<!-- END GCR Language Code -->
kaferklaus, the code is incomplete.
<?php echo $_POST["email"]; ?>
<?php echo $_POST["order_id"]; ?>
is not valid
Hi Creepzn,
which is the right code?
when I enter this code the id and email fields remain empty
<?php echo $_POST["email"]; ?>
<?php echo $_POST["order_id"]; ?>
thanks