Fun with UTI – personalized ‘Welcome back’ message.

0

If You visit any Zen Cart store You may notice greeting message that says something like ‘Welcome Guest! Would you like to log yourself in?‘. Have You ever wondered what’s purpose of this message? Does it give any information to the visitor? Does it make him feel special? Does it serve any purpose other then providing link to ‘Log In’ page? No, it does not. Zen Cart displays personalized greetings like ‘Welcome back, John!‘, but only to registered users who are already logged in.

Default Zen Cart greeting message to Guest visitors.

Compare it to Amazon store. Let’s say that the visitor (John)  has account there and occasionally visits their website. Every time he goes back he is greeted with personalized message: ‘Hello, John. We have recommendations for You.‘. John does not have to log in, provide any information or do anything special – yet he is still recognized as returning customer. How’s that different from Zen Cart greeting?

  • John knows that he already has account at Amazon so he does not have to create one
  • John gets personalized message
  • he has access to his shopping cart without logging in
  • he sees his recently viewed products
  • Amazon recommends some items based on his shopping/browsing history
  • even if the visitor is not John Johns identity and private data is not revealed.

Pretty cool, right? When John visits Amazon.com he feels like he was already logged in (but he’s not). Can Zen Cart to that? Yes, with User Tracking Interface.

UTI to the rescue!

If You’re not familiar with User Tracking Interface (UTI) please read about it here. You will need to install UTI if You want to implement this functionality on Your store.

With UTI We can make Zen Cart a bit more friendly to returning visitors. UTI recognizes returning visitors by cookie, ip address or both and stores basic information about them (time of last visit, last IP address, customer ID if visitor created account).

What We need to do

  • check if UTI recognized the visitor as returning customer (UTI does it automatically)
  • if it did We display personalized message

Code

We’ll be working with default template that comes with Zen Cart: template_default. In case of custom templates the same steps should be applied.

Zen Cart uses zen_customer_greeting() function to display greeting message to the visitor. Here’s snippet of code that uses this function (includes/templates/template_default/templates/tpl_index_default.php), lines 19-21:

<?php if (SHOW_CUSTOMER_GREETING == 1) { ?>
<h2 class="greeting"><?php echo zen_customer_greeting(); ?></h2>
<?php } ?>

Unfortunately We can’t use zen_customer_greeting() as We don’t want to change Zen Cart core code. We’ll create our own greeting function instead. We’ll put it in includes/functions/extra_functions/personalized_greeting.php.

<?php
function personalized_greeting() {
    global $uti;
    global $db;
    // revert back to default greeting function if the visitor is not recognized by UTI
    if(!isset($uti)) return(zen_customer_greeting());
    if( !isset($uti->customerID) || ((int)$uti->customerID) == 0) return(zen_customer_greeting());
   
    // UTI recognizes the visitor as returning customer, let’s get his first name
    $q = $db->Execute("SELECT * FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int)$uti->customerID);
    return(sprintf(TEXT_GREETING_PERSONAL, zen_output_string_protected($q->fields[‘customers_firstname’]), zen_href_link(FILENAME_PRODUCTS_NEW)));

}
?>

We reuse default Zen Cart greeting message, TEXT_GREETING_PERSONAL. We now need to modify our template to use personalized_greeting() instead of zen_customer_greeting(). Go to includes/templates/template_default/templates/tpl_index_default.php and change:

<?php if (SHOW_CUSTOMER_GREETING == 1) { ?>
<h2 class="greeting"><?php echo zen_customer_greeting(); ?></h2>
<?php } ?>

to:

<?php if (SHOW_CUSTOMER_GREETING == 1) { ?>
<h2 class="greeting"><?php echo personalized_greeting(); ?></h2>
<?php } ?>

And that’s it! From now on returning customers will be greeted with personalized message.

Test

Visit Your store and create test account. Close Your browser and return to Your website after half hour. Default  Zen Cart session lifespan is 15 minutes so any saved Zen Cart session should be invalidated by now. If our little module works correctly You should be greeted by Your name.

Personalized greeting message to returning customers (using UTI)

Download

For Your convenience I prepared .zip file with personalized_greeting() function. You can download it here. However, You’ll have to make necessary changes to the template yourself.

Download the package.

Remember that You have to have UTI installed for this module to work.

Posted in: Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

*




You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free

Social Stuff

Donate

If You like Query Cache, Query Log or Randomized Tests please make a $5 donation.

Search the blog