My goal is to print a conversion tracking code after a Paypal payment.
It seemed easy to put the conversion tracking code in complete.tpl between {if $ispaid} and {/if}, even if a required var "amount" was missing.
The problem is that after a Paypal payment on paypal.com, I'm not taken back to /cart.php?a=complete , but to the invoice /viewinvoice.php?id=xxxx , even if the "Automatically forward the user to the payment gateway" is checked in Options. Well, it's true I'm forwarded to the payment gateway, Paypal in this case, but after the payment I'm taken to the invoice rather to the complete/thank you page.
In desperation, I tried to hook into InvoicePaid and made a function to echo the code there, in the invoice. But it doesn't work either, nothing is echoed.
/includes/hooks/csw.php (custom file):
Could anybody kindly shed some light on this thing please?
Thank you in advance.
It seemed easy to put the conversion tracking code in complete.tpl between {if $ispaid} and {/if}, even if a required var "amount" was missing.
PHP Code:
{if $ispaid}
<!-- Enter any HTML code which needs to be displayed once a user has completed the checkout of their order here - for example conversion tracking and affiliate tracking scripts -->
{/if}
In desperation, I tried to hook into InvoicePaid and made a function to echo the code there, in the invoice. But it doesn't work either, nothing is echoed.
/includes/hooks/csw.php (custom file):
PHP Code:
// copy paste of function found in whmcs docs online
function csw_xml_parser($rawxml) {
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $rawxml, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
$alreadyused = array();
$x=0;
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (in_array($xml_elem['tag'],$alreadyused)) {
$x++;
$xml_elem['tag'] = $xml_elem['tag'].$x;
}
$level[$xml_elem['level']] = $xml_elem['tag'];
$alreadyused[] = $xml_elem['tag'];
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
@eval($php_stmt);
}
}
return($params);
}
function csw_InvoicePaid( $vars )
{
$invoiceid = $vars['invoiceid'];
$invoiceXML = localAPI('getinvoice',array('invoiceid'=>"$invoiceid"),'admin');
$invoice = csw_xml_parser($invoiceXML);
// debug to see what invoice looks like
return '<pre>'.print_r( $invoice, true ).'</pre>';
}
add_hook("InvoicePaid",1,"csw_InvoicePaid");
Thank you in advance.