How to personalize homepage by adding customer’s name in nopCommerce

The magic of creating personalize experience comes from the data. Many store owners do not make use of the customer data that they already have in their database. Making use of existing data and creating a personalize experienced for online shoppers is a great way to bring back existing customers to your store site.

Statistics shows that consumers like when online stores offers personalize messages and offers. User data can be used in several ways to personalize the communication between the online store and the potential buyers.

Today, we will discuss how to personalize homepage by adding customer’s name to it in nopCommerce.


Go to: Nop.Web / Views / Home / Index.cshtml


Open the file “Index.cshtml” and add this code at the top:


@using Nop.Core
@using Nop.Core.Domain.Customers
@using Nop.Core.Infrastructure
@using Nop.Services.Common


By adding the above code, we are simply loading the customer data from the database. Once, we have the data loaded, we can display it in any way (or anywhere).


Add the following code on the same “Index.cshtml” page (in the body where you would like to display the customer’s name):


            var currentCustomer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;

            if (!currentCustomer.IsGuest())
                var name = currentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName);

                if (!string.IsNullOrEmpty(name))
                    <div id="customnameLabel" style="display: inline-block;">YourStore Welcomes You:</div> <div id="customnameValue" style="font-weight:bold;display: inline-block;">@name</div>


In this example, we are adding the customer’s “first name” (pulling it from the database).


Here is the output:



Note: One of the best feature of this code is  that, the name will “only” show up if customer is logged in. No name will be displayed if any guest visitor is viewing the store site.


 Looking for quality nopCommerce Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , | Posted under nopCommerce | RSS 2.0

Author Spotlight

Lavish Kumar

Founder, developer and owner of - By profession, he is a software programmer / web developer, web designer & DBA. He is passionate about technology and electronic gadgets. He enjoys writing tech articles and developing web applications. He is a nopCommerce MVP and author of official nopCommerce Designer's Guide.

Leave a Reply

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