Code: Select all
<script>
gtag('event', 'conversion', {
'send_to': 'AW-661773975/VUAlCOOF3cgBEJe9x7sC',
'value': '<?php echo $total; ?>',
'currency': 'CZK',
'transaction_id': ''
});
</script>
This one: viewtopic.php?t=202389#p715162
Puts code in the <head> tag if the page is checkout success. This works fine.
Then this one: https://stackoverflow.com/questions/199 ... javascript
Should make the 'order_id' and 'total' variables available from the template files on checkout success page.
This doesn't work for me, I keep getting a PHP undefined variable 'order_id' error. If I remove the 'order_id' condition, the undefined variable 'total' error is within the javascript (so at least the customer can't see it).
What I did so far:
In my catalog/controller/common/header.php file, in the index() method, I added:
Code: Select all
if (!empty($this->request->get['route'])) {
$data['route'] = $this->request->get['route'];
} else {
$data['route'] = '';
}
Code: Select all
<?php if (!empty($route) && $route == 'checkout/success') { ?>
<?php if($order_id) { ?>
<script>
gtag('event', 'conversion', {
'send_to': 'AW-661773975/VUAlCOOF3cgBEJe9x7sC',
'value': '<?php echo $total; ?>',
'currency': 'CZK',
'transaction_id': ''
});
</script>
<?php } ?>
<?php } ?>
Code: Select all
public function index() {
$data['order_id'] = 0; // <-- NEW LINE
$data['total'] = 0; // <-- NEW LINE
if (isset($this->session->data['order_id'])) {
$data['order_id'] = $this->session->data['order_id']; // <-- NEW LINE
$data['total'] = $this->cart->getTotal(); // <-- NEW LINE
What am I doing wrong? I'm not very good in OC's internal matters, but is it possible that in order to make the 'order_id' and 'total' variables available from header.tpl, I need to put the lines commented as NEW LINE in header.php instead of success.php? If that's the case, can I simply find an index() function in header.php and copy those lines there the same way as for success.php, or do I need to do it differently?
Thank you very much.
Petr Břeň