I think the best solution is to check if a customer has made any order.
So in your case try to load all the customer that you have like this ;
You need to inject \Magento\Customer\Model\Customer class to get customer collection
<?php
protected $_customers;
public function __construct(
...
\Magento\Customer\Model\Customer $customers
...
) {
...
$this->_customers = $customers;
...
}
public function getCollection()
{
//Get customer collection
return $this->_customers->getCollection();
}
public function getCustomer($customerId)
{
//Get customer by customerID
return $this->_customers->load($customerId);
}
}
Now you can get customer collection or customer by customerID in phtml file
<?php
//Get customer collection
$collection = $this->getCollection();
foreach ($collection as $customer) {
echo $customer->getEmail(); // Get Customer Email
}
//Get customer by ID
$customerId = 1;
$customer = $this->getCustomer($customerId);
echo $customer->getEmail(); // Get customer Email
?>
and then check if they have any order
This will check the first order of the customer. If the customer dosen't have a "first order' this means that he/she didn't order anything yet.
<?php
namespace Namespace\Module\Block;
class Test extends \Magento\Framework\View\Element\Template
{
protected $orderFactory;
public function __construct(
\Magento\Sales\Model\OrderFactory $orderFactory
) {
$this->orderFactory = $orderFactory;
}
public function getFirstOrder($emailId){
$emailId = '[email protected]';
$order = $this->orderFactory->create()->getCollection()->addAttributeToSelect('customer_email')
->addFieldToFilter('customer_email',array('eq'=>$emailId))->getFirstItem();
if($order->getCustomerEmail()){
echo 'second time order';
}
else{
echo 'first time order';
}
}
So you need to load all the customer and then make a foreach and check for each if they have first order or not. I hope this will help.