/** * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. * @access public * @since 1.0.0 * @param int $course_id (default: 0) * @param array/Object $order_user (default: array()) Specific user's data. * @return bool|int */ public function woocommerce_course_update($course_id = 0, $order_user = array()) { global $current_user; if (!isset($current_user) || !$current_user->ID > 0) { return false; } $data_update = false; // Get the product ID $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true); // Check if in the admin if (is_admin()) { $user_login = $order_user['user_login']; $user_email = $order_user['user_email']; $user_url = $order_user['user_url']; $user_id = $order_user['ID']; } else { $user_login = $current_user->user_login; $user_email = $current_user->user_email; $user_url = $current_user->user_url; $user_id = $current_user->ID; } // End If Statement // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true); if (0 < absint($course_prerequisite_id)) { $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id)); if (!$prereq_course_complete) { // Remove all course user meta return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id); } } $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id)); if (!$is_user_taking_course) { if (Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product($user_email, $user_id, $wc_post_id) && 0 < $wc_post_id) { $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id)); $is_user_taking_course = false; if (true == $activity_logged) { $is_user_taking_course = true; } // End If Statement } // End If Statement } return $is_user_taking_course; }
/** * Outputs the lessons course signup lingk * * This hook runs inside the single lesson page. * * @since 1.9.0 */ public static function course_signup_link() { $course_id = Sensei()->lesson->get_course_id(get_the_ID()); if (empty($course_id) || 'course' != get_post_type($course_id) || sensei_all_access()) { return; } ?> <section class="course-signup lesson-meta"> <?php $wc_post_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true); if (Sensei_WC::is_woocommerce_active() && 0 < $wc_post_id) { global $current_user; if (is_user_logged_in()) { wp_get_current_user(); $course_purchased = Sensei_Utils::sensei_customer_bought_product($current_user->user_email, $current_user->ID, $wc_post_id); if ($course_purchased) { $prereq_course_id = get_post_meta($course_id, '_course_prerequisite', true); $course_link = '<a href="' . esc_url(get_permalink($prereq_course_id)) . '" title="' . esc_attr(get_the_title($prereq_course_id)) . '">' . __('the previous course', 'woothemes-sensei') . '</a>'; ?> <div class="sensei-message info"> <?php echo sprintf(__('Please complete %1$s before starting the lesson.', 'woothemes-sensei'), $course_link); ?> </div> <?php } else { ?> <div class="sensei-message info"> <?php $course_link = '<a href="' . esc_url(get_permalink($course_id)) . '"title="' . __('Sign Up', 'woothemes-sensei') . '">' . __('course', 'woothemes-sensei') . '</a>'; echo sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link); ?> </div> <?php } ?> <?php } else { ?> <div class="sensei-message info"><?php echo sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Sign Up', 'woothemes-sensei') . '">' . __('course', 'woothemes-sensei') . '</a>'); ?> </div> <?php } ?> <?php } else { ?> <?php if (!Sensei_Utils::user_started_course($course_id, get_current_user_id()) && sensei_is_login_required()) { ?> <div class="sensei-message alert"> <?php $course_link = '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Sign Up', 'woothemes-sensei') . '">' . __('course', 'woothemes-sensei') . '</a>'; if (Sensei_Utils::is_preview_lesson(get_the_ID())) { echo sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link); } else { echo sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link); } ?> </div> <?php } ?> <?php } // End If Statement ?> </section> <?php }
/** * Prints out the course action buttons links * * - complete course * - delete course * * @param WP_Post $course */ public static function the_course_action_buttons($course) { if (is_user_logged_in()) { ?> <section class="entry-actions"> <form method="POST" action="<?php echo esc_url(remove_query_arg(array('active_page', 'completed_page'))); ?> "> <input type="hidden" name="<?php esc_attr_e('woothemes_sensei_complete_course_noonce'); ?> " id="<?php esc_attr_e('woothemes_sensei_complete_course_noonce'); ?> " value="<?php esc_attr_e(wp_create_nonce('woothemes_sensei_complete_course_noonce')); ?> " /> <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e(intval($course->ID)); ?> " /> <?php if (0 < absint(count(Sensei()->course->course_lessons($course->ID))) && Sensei()->settings->settings['course_completion'] == 'complete' && !Sensei_Utils::user_completed_course($course, get_current_user_id())) { ?> <span><input name="course_complete" type="submit" class="course-complete" value="<?php _e('Mark as Complete', 'woothemes-sensei'); ?> " /></span> <?php } // End If Statement $course_purchased = false; if (Sensei_WC::is_woocommerce_active()) { // Get the product ID $wc_post_id = get_post_meta(intval($course->ID), '_course_woocommerce_product', true); if (0 < $wc_post_id) { $user = wp_get_current_user(); $course_purchased = Sensei_Utils::sensei_customer_bought_product($user->user_email, $user->ID, $wc_post_id); } // End If Statement } // End If Statement if (!$course_purchased && !Sensei_Utils::user_completed_course($course->ID, get_current_user_id())) { ?> <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __('Delete Course', 'woothemes-sensei'); ?> "/></span> <?php } // End If Statement $has_quizzes = Sensei()->course->course_quizzes($course->ID, true); $results_link = ''; if ($has_quizzes) { $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink($course->ID) . '">' . __('View results', 'woothemes-sensei') . '</a>'; } // Output only if there is content to display if (has_filter('sensei_results_links') || $has_quizzes) { ?> <p class="sensei-results-links"> <?php /** * Filter the results links * * @param string $results_links_html * @param integer $course_id */ echo apply_filters('sensei_results_links', $results_link, $course->ID); ?> </p> <?php } // end if has filter ?> </form> </section> <?php } // end if is user logged in }