I've seen that there is a Customer Type column in the in-built Analytics. Can someone tell me the php code for this? I want to use it somewhere else and it seems like a ready function which I could call upon.
Thanks!
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI've seen that there is a Customer Type column in the in-built Analytics. Can someone tell me the php code for this? I want to use it somewhere else and it seems like a ready function which I could call upon.
Thanks!
A custom function would be required. You can check for any orders placed by customer details, but I'd recommend using either customer id (best option as you can get the logged in user's id very easily) or customer email address..
function wpse419519_is_returning_customer( $customer ) {
$args = array(
'limit' => -1, //Returns all the orders
);
if ( is_email($customer) ) { //If you want to check with email address
$args['customer'] = $customer;
} else {
$args['customer_id'] = $customer;
}
$orders = wc_get_orders( $args );
if ( !empty($orders) ) {
return true;
}
return false;
}
You can now call wpse419519_is_returning_customer()
anywhere after the user is authenticated to check if it is a returning customer. For example:
$is_returning = wpse419519_is_returning_customer(get_current_user_id());
if ($is_returning) {
//Returning customer
} else {
//New customer
}