Jump to content

Displaying clientdetails in shopcartcomplete page or order confirmation page


rahulkg

Recommended Posts

Hi,

I just wanted to show some clientdetails in orderconfirmation page (complete.tpl) . For this I wrote a hook like this

function reviewCode($vars)
{
    
    $extraTemplateVariables = array();
$extraTemplateVariables['orderid']=$vars['orderid'];
 $extraTemplateVariables['fn']=$vars['clientdetails']['firstname'];
 $extraTemplateVariables['lt']=$vars['clientdetails']['lastname'];
 $extraTemplateVariables['em']=$vars['clientdetails']['email'];

return $extraTemplateVariables;
 }
add_hook("ShoppingCartCheckoutCompletePage", 1, "reviewCode");

and tried to display in orderconfirmation page using {$clientdetails.firstname} and I got it displayed. but I see 'Array' there. when checking I see it comes from whmcs code 

 {foreach $addons_html as $addon_html}
                <div class="order-confirmation-addon-output">
                    {$addon_html}
                </div>
            {/foreach} why it so ? why returning array containing values in ShoppingCartCheckoutCompletePage hook affect the foreach code ?  and it seems like the returned values get collected in $addons_html variabkle. so what to be done to remove the Array showing in the orderconfirmation page?

Link to comment
Share on other sites

50 minutes ago, rahulkg said:

why it so ?

it's worth noting what the dev docs say about that hook point...

Quote

Response: Return HTML to be displayed on the order complete page.

the hook returns HTML - and not an array like your hook wants to do. ⚠️

so you either get the hook to return the HTML you want to show on the complete page, or you edit the complete.tpl template directly (the variables will be available to the template) - continuing to use the hook is probably the better method going forward...

an example ShoppingCartCheckoutCompletePage hook is showing below - slightly more involved than what you need as it involves a db query which you won't need...

untested, but I would imagine your hook would be along the lines of..

<?php

# Shopping Cart Complete Page Output Hook
# Written by brian!

add_hook('ShoppingCartCheckoutCompletePage', 1, function($vars) {
	
	$output = "Your name is ".$vars['clientsdetails']['firstname']." ".$vars['clientsdetails']['lastname']." and your Order ID is: ".$vars['orderid'].";
	return $output;
});

note that by the time a user reaches the complete page, they will already be logged in - so there would be many ways of getting information about them other than by using clientsdetails.

Link to comment
Share on other sites

Hi Brian,

But I see  the word 'Array' got displayed n order confirmation page ,  and I didnt want to return any html  content to the complete.tpl (because I need these values to insert in a review script code , not just for showing like that as you written there ), I just need clientdetails firstname, lastname, orderid and email in complete.tpl file. and got all these values displayed in order confirmation page but now just need to get rid of the word 'Array' showing there. (Its the only thing I needed now) ( Also I know why it shows Array because of following code 

{foreach $addons_html as $addon_html}
                <div class="order-confirmation-addon-output">
                    {$addon_html}
                </div>
            {/foreach}

and I got rid of 'Array' by changing  above code to 
{foreach $addons_html as $addon_html}

{foreach $addon_html as $item}
                <div class="order-confirmation-addon-output">
                    {$item}
                </div>

  {/foreach}
            {/foreach} ( Here its clear that my returned array values are collected in $addon_html variable and I need to foreach it again like above to avoid that issue .
But what I afraid is whether  this modification will create any issue in order confirmation page ?  and I also what I wonder is that why the returned array values from hook get collected in the array variable  $addon_html
 ?

Edited by rahulkg
Link to comment
Share on other sites

Hi Rahul,

1 minute ago, rahulkg said:

But I see  the word 'Array' got displayed n order confirmation page ,  and I didn't want to return any html  content to the complete.tpl, I just need clientdetails firstname, lastname, orderid and email in complete.tpl file.

by html content, it can just be plain text and not necessarily HTML code.

2 minutes ago, rahulkg said:

and I got rid of 'Array' by changing  above code to 

it would have been easier to leave that foreach code alone and just use the hook correctly! 🙄

3 minutes ago, rahulkg said:

Here its clear that my returned array values are collected in $addon_html variable and I need to foreach it again like above to avoid that issue .

the template code is not the issue - leave it alone! 🙂

3 minutes ago, rahulkg said:

But what I afraid is whether  this modification will create any issue in order confirmation page ?

it shouldn't - though it cripples the effective and the purpose of using that hook point in the first place...

14 minutes ago, rahulkg said:

and I also what I wonder is that why the returned array values from hook get collected in the array variable  $addon_html  ?

because it's not expecting you ro return an array.

if you're going to edit the template to change this foreach code (which you shouldn't), then you shouldn't even need the hook to pass the variables - they will already exist and be available to the template.... that's why {$clientsdetails.firstname} works with or without the hook.

so in the template if you add {$clientsdetails.firstname}, then it should echo the client's firstname... similarly for all the other variables the hook is trying to pass, e.g lastname, orderid etc.... if you get stuck, just add {debug} to the template and it will generate a popup window of available variables the next time you visit/refresh the page.

 

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