New Vs Old Customer Variable

Trying to get help from cs-cart team, but it looks like they just don't care about existing customers. Ticket is open for 3 days and no answer.

I have a question for cs-cart gurus that we still have on this forum:

Trying to setup an affiliate pixel and how do we determine new vs old customer?

My affiliate support team is telling me:

"Most other carts we’ve worked with allow you to determine the number of previous orders for a customer. If they have 0, then they are a new customer."

We have tried to use ' $auth.user_id ' variable, but it is not really working as it outputs 0 for new and customer id ( a 5 digit numbers) for existing customers.

What we need is to output: 0 for existing customers and 1 for new. The problem is, when guest checkout is used, the variable ' $auth.user_id ' is also outputs '0'

Any suggestions on how to solve this issue?

Thanks,
Xmaster

You can use the following code to get orders count

{$orders_count = "SELECT COUNT(order_id) FROM ?:orders WHERE user_id = ?i"|db_get_field:$auth.user_id}

But it will not solve issue with anonymous customer. What do you want to do for them?

Hi eComLabs Team,

You mean customers who checkout as guest? Can we possibly check if email exist on our system, and if YES then treat as existing customer and if NO means new customer.

You can use the following code to get orders count

{$orders_count = "SELECT COUNT(order_id) FROM ?:orders WHERE user_id = ?i"|db_get_field:$auth.user_id}

But it will not solve issue with anonymous customer. What do you want to do for them?

Hi eComLabs Team,

You mean customers who checkout as guest? Can we possibly check if email exist on our system, and if YES then treat as existing customer and if NO means new customer.

On what page this information is required?

The code is executed on Order Confirmation / "Thank you for your order" page.

On what page this information is required?

The code is executed on Order Confirmation / "Thank you for your order" page.

Received following reply from cs-cart team, perhaps it will help to solve the issue.

"In the $auth.user_id there will be zero value in case when user is not authorized. Otherwise there will be the number of his/her user_id.

In order to determine if the user is new or not, you can check this user's creation timestamp. You can either get the timestamp manually from the database table cscart_users by the user_id, or otherwise - call the fn_get_user_info function by passing to it the user_id and in the result check the timestamp element of the returned array."

The code is executed on Order Confirmation / "Thank you for your order" page.

use this code

{$orders_count = "SELECT COUNT(order_id) FROM ?:orders WHERE email = ?s"|db_get_field:$order_info.email}

Thank you!

Will test and report back.

use this code

{$orders_count = "SELECT COUNT(order_id) FROM ?:orders WHERE email = ?i"|db_get_field:$order_info.email}

Thank you!

Will test and report back.

The Code does not really work, as it is not returning anything.

The Code does not really work, as it is not returning anything.

How do you use the result then?

P.S. Just found a mistake. In the request replace ?i with ?s

Unfortunately, it is not outputting anything.

I have checked page source after checkout and here how it looks when using your code.

var uts_orderscount='';

How do you use the result then?

P.S. Just found a mistake. In the request replace ?i with ?s

Please provide us with the full code and template you use