/** * sensei_check_prerequisite_course function. * * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); * @access public * @param mixed $course_id * @return bool */ function sensei_check_prerequisite_course($course_id) { return Sensei_Course::is_prerequisite_complete($course_id); }
/** * Show the WooCommerce add to cart button for the current course * * The function will only show the button if * 1- the user can buy the course * 2- if they have completed their pre-requisite * 3- if the course has a valid product attached * * @since 1.9.0 * @param int $course_id * @return string $html markup for the button or nothing if user not allowed to buy */ public static function the_add_to_cart_button_html($course_id) { if (!Sensei_Course::is_prerequisite_complete($course_id)) { return ''; } $wc_post_id = self::get_course_product_id($course_id); // Check if customer purchased the product if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id) || empty($wc_post_id)) { return ''; } // based on simple.php in WC templates/single-product/add-to-cart/ // Get the product $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); // do not show the button for invalid products, non purchasable products, out // of stock product or if course is already in cart if (!isset($product) || !is_object($product) || !$product->is_purchasable() || !$product->is_in_stock() || self::is_course_in_cart($wc_post_id)) { return ''; } // // button output: // ?> <form action="<?php echo esc_url($product->add_to_cart_url()); ?> " class="cart" method="post" enctype="multipart/form-data"> <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?> " /> <input type="hidden" name="quantity" value="1" /> <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?> <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?> " /> <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?> <?php foreach ($product->variation_data as $att => $val) { ?> <input type="hidden" name="<?php echo esc_attr($att); ?> " id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?> " value="<?php echo esc_attr($val); ?> " /> <?php } ?> <?php } ?> <?php } ?> <button type="submit" class="single_add_to_cart_button button alt"> <?php echo $product->get_price_html(); ?> - <?php _e('Purchase this Course', 'woothemes-sensei'); ?> </button> </form> <?php }