function getDateOfLastOrder($account_id) { global $wpdb; $lastdate = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT LastTimeModified\n\t\t\tFROM {$this->tablename}\n\t\t\tWHERE account_id = %s\n\t\t\tORDER BY LastTimeModified DESC LIMIT 1\n\t\t", $account_id)); // if there are no orders yet, check the date of the last transaction if (!$lastdate) { $tm = new TransactionsModel(); $lastdate = $tm->getDateOfLastCreatedTransaction($account_id); if ($lastdate) { // add two minutes to prevent importing the same transaction again $lastdate = mysql2date('U', $lastdate) + 120; $lastdate = date('Y-m-d H:i:s', $lastdate); } } return $lastdate; }