I want to show list of the guest user in my custom module. Which is the best way to get the list of the guest order.

How can i get list of the guest orders?

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $lastyear = date('Y-m-d', strtotime("-1 year"));

  $order = $objectManager->create('Magento\Sales\Model\Order')->getCollection()->addAttributeToFilter('customer_id', $customer_id)->addAttributeToFilter('state', 'complete')->addAttributeToFilter('created_at', ['gteq'  => $lastyear]);

To get the guest orders i am getting collection of all the orders and checking customer email address. If user with that email address doesn't exist then consider it as guest order.

Is this correct flow? Is there any other flow to check guest orders?

Any help would be appreciated.

2 Answers 2


You can get guest customer order list by below code.

public function __construct(
    \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,

) {
    $this->orderCollectionFactory = $orderCollectionFactory;

public function getGuestOrderCollection()
    $orderCollecion = $this->orderCollectionFactory

    $orderCollecion->addAttributeToFilter('customer_is_guest', ['eq'=>1]);

    echo "<pre>";
    return $orderCollecion;
  • Thanks for help. what's the use of following code? $totalGuestOrder = $this->getRequest()->getParam('total_guest_order'); if ('all' !== $totalGuestOrder){ $orderCollecion->getSelect()->limit((int)$totalGuestOrder); } Is it possible for you to explain?
    – jack
    Jan 30, 2018 at 11:08
  • Check my updated answer, this code is not for you. Jan 30, 2018 at 11:10
  • Thanks suresh but can you tell me what's the use of that code. I am learner so it would help me.
    – jack
    Jan 30, 2018 at 11:13
  • Which code are use for curl request, in your case it was not useful. From above code you will get list of guest users order list. Jan 30, 2018 at 11:15
  • Ok thanks. If i want to print this collection then $orderCollection->getData() will work? or $this->_logger->debug($orderCollecion);
    – jack
    Jan 30, 2018 at 11:17

Please use below code to get list of guest orders:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')
            ->addAttributeToFilter('customer_is_guest', ['eq'=>1]);

Your Answer

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

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