SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH
get all customers in Magento 2
Magepow.com

How to get all customers in Magento 2

Hi everyone, Today I will guide you how to get all customers in Magento 2.

Step 1. Create block file Magepow/AllCustomers/Block/AllCustomers.php with content bellow:

namespace Magepow/AllCustomers/Block;

use Magento\Backend\App\Action;


class AllCustomers extends Action
{

    protected $customerCollection;

    public function __construct(
        \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollection
    )
    {
        $this->customerCollection = $customerCollection;
    }

    public function getAllCustomers()
    {
            return $this->customerCollection->create();


    }
}

Now we call the function in the template and get data.

$allCustomers = $this->getAllCustomers();
foreach ($allCustomers as $customer) {
    echo $customer->getEmail();
    echo $customer->getFirstname();
    echo $customer->getLastname();
}

Done, If you have any questions, please leave a comment.