<?php 
$upload_dir = wp_upload_dir();
// fetch images of status = 2
$args = array('post_status' => 'any', 'post_type' => 'attachment', 'posts_per_page' => -1, 'meta_query' => array(array('key' => 'image_status', 'value' => 2, 'compare' => '=')));
$q = new WP_Query($args);
while ($q->have_posts()) {
    $q->the_post();
    $feat_image = wp_get_attachment_url(get_the_ID());
    $str = explode('/', $feat_image);
    $file_name = get_the_id() . '_' . end($str);
    copy($upload_dir['basedir'] . "/2015/10/" . end($str), $upload_dir['basedir'] . "/ordered-images/" . $file_name);
    $filelist[] = $file_name;
}
wp_reset_postdata();
$zipname = call_to_zip($filelist);
$link = get_bloginfo('url') . '/' . $zipname . '';
// make zip file
function call_to_zip($filelist)
{
    $upload_dir = wp_upload_dir();
    $zipname = 'order.zip';
    $zip = new ZipArchive();
    $zip->open($zipname, ZipArchive::CREATE);
    if ($handle = opendir($upload_dir['basedir'] . '/ordered-images/')) {
        for ($i = 0; $i < count($filelist); $i++) {
            $str = explode('/', $filelist[$i]);
            $entry = end($str);
            $zip->addFile($upload_dir['basedir'] . '/ordered-images/' . $entry, $entry);
        }
    }
$q = new WP_Query($arg2);
while ($q->have_posts()) {
    $q->the_post();
    $project_id = get_the_ID();
    if (!empty($project_id)) {
        // count all images in each project(where image status = (can be any one like 1 , 2,3) and project status = 2)
        $arg3 = array('post_status' => 'any', 'post_type' => 'attachment', 'posts_per_page' => -1, 'author' => $user_ID, 'meta_query' => array(array('key' => 'group_id', 'value' => $project_id, 'compare' => '=', 'type' => 'numeric')));
        $imagecount_in_project = count(query_posts($arg3));
        // count images in each project(where image status =3 and project status = 2)
        $arg4 = array('post_status' => 'any', 'post_type' => 'attachment', 'posts_per_page' => -1, 'author' => $user_ID, 'meta_query' => array('relation' => 'AND', array('key' => 'group_id', 'value' => $project_id, 'compare' => '=', 'type' => 'numeric'), array('key' => 'image_status', 'value' => 3)));
        $closed_images_of_project = count(query_posts($arg4));
        // update project status if its all images has edited
        if (!empty($imagecount_in_project) && !empty($closed_images_of_project)) {
            if ($imagecount_in_project == $closed_images_of_project) {
                update_post_meta($project_id, 'image_project_status', '3');
                $zipname = call_to_zip($project_id);
                $ORDER_NUMBER = $project_id;
                $CLIENT_NAME = ucfirst(get_user_fname1($user_ID)) . '' . ucfirst(get_user_lname1($user_ID));
                $LINK = get_bloginfo('url') . '/' . $zipname . '';
                // multiple recipients
                $to = get_user_email1($user_ID);
                if (ICL_LANGUAGE_CODE == 'fr') {
                    // subject
                    $subject = 'Mon projet Immopix Fermé';
                    // message
                    $message = '<div class="myemail"> Bonjour ' . $CLIENT_NAME . ':<br><br>
									Félicitations! Nous avons chargé les photos retouchées de votre commande <ORDER NUMBER>. ' . $ORDER_NUMBER . '.<br><br>
									Veuillez suivre le lien suivant pour télécharger vos images retouchées ::<br><br>
									' . $LINK . '<br><br>
									Les images resteront sur myimmopix.com pour 90 jours. Elles serotn ensuite supprimées. Merci donc de les télécharger le plus tôt possible.<br><br>