FavoriteLoadingAdd to favorites

Send an email if there are any woocommerce orders created a before the current Day.

$wp_query = new WP_Query(
    array(
        'posts_per_page'=> -1,
        'post_type'=>'shop_order',
        'post_status'=>'wc-processing',
        // 'post_status'=>'wc-completed',
        // 'post_status'=>'wc-pending',
        // 'post_status'=>'wc-canceled',
    )
);
$message = "These orders are curently processing<br>";
$confirm_mail_send = 0;   
foreach ($wp_query->posts as $order) {
        date_default_timezone_set('Africa/Johannesburg');
        $current_date = strtotime(date('Y-m-d'));
        // echo $current_date."<br>";
        
        $post_date = $order->post_date;
        $post_date_exploded = explode(' ', $post_date);
        $post_date_for_diff = strtotime($post_date_exploded[0]);
        // echo $post_date_for_diff."<br>";

        $diff =  $current_date - $post_date_for_diff;
        // echo $diff."<br>";
        
        function secondsToTime($seconds) {
            $dtF = new \DateTime('@0');
            $dtT = new \DateTime("@$seconds");
            return $dtF->diff($dtT)->format('%a days');
        }
        // echo secondsToTime($diff);
        
        if ($diff > 1) {
            $href = 'https://tjhokopaint.co.za/wp-admin/post.php?post='.($order->ID).'&action=edit'; 
            $message .= '<a href="'.$href.'">Order: '.$order->ID.'</a> ';
            $confirm_mail_send++;
            // echo "True";
        }
}
echo $message;
if ($confirm_mail_send != 0) {
    $to = 'garth@webfootprint.co.za';
    $subject = 'Pending Orders';
    $headers = array('Content-Type: text/html; charset=UTF-8');
    wp_mail( $to, $subject, $message, $headers);
}

 

Pin It on Pinterest

Share This