Categories
Magento Tips and Tricks

Export Guest customers in Magento 1.*

There are times when you want to promote your products to a guest customer. You might want to send newsletters or promos to a guest customer to bring them back and buy your products or for marketing campaigns.

But Magento doesn’t provide any way to export guest customer from admin panel. So, we will learn an easy way to export guest customer on your Magento website.

First of all, create a new PHP file named “guest-customer.php” in a root directory of your Magento installation.

Secondly, add following lines of code in “guest-customer.php” file and save it.

<?php
header('Content-Type: application/excel');
header('Content-Disposition: attachment; filename="guest-customer.csv"');
/* Magento's Mage.php path
 * Mage Enabler users may skip these lines
 */
require_once("app/Mage.php");
Mage::app();
/* Magento's Mage.php path */

$orderCollection = Mage::getModel("sales/order")->getCollection()
    ->addFieldToFilter('customer_is_guest', 1)
    ->addFieldToSelect('*');
$fp = fopen('php://output', 'w');
foreach ($orderCollection as $eachorder) {
    fputcsv($fp, array(
        $eachorder->getCustomerFirstname(),
        $eachorder->getCustomerLastname(),
        $eachorder->getCustomerEmail()
    ));
}
fclose($fp);

Finally, go to your favorite browser and type “http://yourwebsitedomain.com/guest-customer.php”. Guest customer lists will be downloaded in CSV format. You can use this file to import in services like Mailchimp to send your promo newsletter.