function learn_press_send_user_email_order($status, $order_id) { $status = strtolower($status); if ('completed' == $status) { $order = new LPR_Order($order_id); $mail_to = $order->get_user('email'); $instructors = array(); $course_title = ''; $transaction_object = $order->get_items(); $items = $transaction_object->products; $item = array_shift($items); $course = get_post($item['id']); $course_title = get_the_title($item['id']); $instructor = LPR_User::instance($course->post_author); $instructors[$instructor->ID] = $instructor->data->display_name; learn_press_send_mail($mail_to, 'enrolled_course', apply_filters('learn_press_vars_enrolled_course', array('user_name' => $order->get_user('display_name'), 'course_name' => $course_title, 'course_link' => get_permalink($item['id'])), $course, $instructor)); } }
/** * get confirm order URL * * @param int $order_id * @return string */ function learn_press_get_order_confirm_url($order_id = 0) { $url = ''; if (($confirm_page_id = learn_press_get_page_id('taken_course_confirm')) && get_post($confirm_page_id)) { $url = get_permalink($confirm_page_id); if ($order_id) { $url = join(preg_match('!\\?!', $url) ? '&' : '?', array($url, "order_id={$order_id}")); } } else { $order = new LPR_Order($order_id); if (($items = $order->get_items()) && !empty($items->products)) { $course = reset($items->products); $url = get_permalink($course['id']); } else { $url = get_site_url(); } } return $url; }
/** * Update course into user's metadata if order status is "Completed" -> user enrolled course * Otherwise, remove course from user's metadata -> user hasn't enrolled course * * @param $status * @param $order_id */ function learn_press_active_user_course($status, $order_id) { $order = new LPR_Order($order_id); $user = $order->get_user(); $course_id = learn_press_get_course_by_order($order_id); $user_course_time = get_user_meta($user->ID, '_lpr_course_time', true); if (strtolower($status) == 'completed') { if (empty($user_course_time[$course_id])) { $user_course_time[$course_id] = array('start' => time(), 'end' => null); } } else { if (!empty($user_course_time[$course_id])) { unset($user_course_time[$course_id]); } } if ($user_course_time) { update_user_meta($user->ID, '_lpr_course_time', $user_course_time); } else { delete_user_meta($user->ID, '_lpr_course_time'); } }