0

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!

WooCommerce Orders Analytics

2

1 Answer 1

0

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.