Jump to content

Get "{$amount}" in template with different currencies


DimaK

Recommended Posts

Hello,

For Google Conversion Tracking I have to add code to "complate.tpl".

Also I think we should use

 var google_conversion_value = {$amount};

to get sale amount.

But my site have 3 currencies!

{$amount} - show just digits in any currency, but to Google, for statistics
I alwas must submit only one USD.

How to get {$amount} converted from any currency to USD ?

Thanks.

 

 

Link to comment
Share on other sites

Use ClientAreaPage action hook to recalculate {$amount} in complete.tpl.

<?php

use WHMCS\Database\Capsule;

function somePrefix_ClientAreaPage($vars)
{
	if ($vars['filename'] == 'cart' AND $_GET['a'] == 'complete')
	{
		$convertTo			= 'USD'; // It's set to USD since Google needs it
		$clientCurrencyID 		= $vars['clientdetails']['currency'];
		$currency			= Capsule::table('tblcurrencies')->select(['code', 'rate', 'default'])->where('id', '=', $clientCurrencyID)->first();

		if ($currency->code != $convertTo AND $currency->default == '0')
		{
			$output['amount'] = $vars['amount'] / $currency->rate;
			return $output;
		}
	}
}

add_hook('ClientAreaPage', 1, 'somePrefix_ClientAreaPage');
Edited by Kian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated