/** * Get an array of all the log IDs using the EDD Logging Class * * @return array if logs, null otherwise * @param $download_id Download's ID */ function get_log_ids($download_id = '') { // Instantiate a new instance of the class $edd_logging = new EDD_Logging(); // get logs for this download with type of 'sale' $logs = $edd_logging->get_logs($download_id, 'sale'); // if logs exist if ($logs) { // create array to store our log IDs into $log_ids = array(); // add each log ID to the array foreach ($logs as $log) { $log_ids[] = $log->ID; } // return our array return $log_ids; } return null; }
/** * Assign selected courses to members of a paticular level. * @param Level ID in which members will get courses enrollment adjusted. */ protected function retroactive_assignment($level_ID) { //Get all transactions from EDD $logging = new EDD_Logging(); $transactions = $logging->get_logs($level_ID); $payment_ids = array(); $customer_ids = array(); //Convert log entries into payment IDs if ($transactions) { foreach ($transactions as $key => $transaction) { $payment_ids[] = get_post_meta($transaction->ID, '_edd_log_payment_id', true); } } //Get IDs that are member of membership level if (count($payment_ids) > 0) { foreach ($payment_ids as $key => $payment_id) { $customer_ids[$key] = get_post_meta($payment_id, '_edd_payment_user_id', true); } } //clean up duplicate IDs $customer_ids = array_unique($customer_ids); $page = new PageBuilder(false); //Enroll members of level if (count($customer_ids) > 0) { foreach ($customer_ids as $customer_id) { $memberLevels = edd_get_users_purchased_products($customer_id); $userLevels = array(); foreach ($memberLevels as $key => $memberLevel) { $userLevels[$key] = $memberLevel->ID; } // Over to the parent class to handle the sync of data. parent::handle_courseSync($customer_id, $userLevels); $page->showMessage(__('All members were successfully retroactively enrolled into the selected courses.', 'wp_courseware')); } return; } else { $page->showMessage(__('No existing members found for the specified level.', 'wp_courseware')); } }