public static function mp2_product_settings($content, $course_id) { $course = new Course((int) $course_id); $paid_course = CoursePress_MarketPress_Integration::is_active() || cp_use_woo() ? $course->details->paid_course : false; $auto_sku = $course->details->auto_sku; $mp_settings = get_option('mp_settings'); $gateways = 0; $settings_gateways = (array) $mp_settings['gateways']; if (isset($settings_gateways['allowed'])) { foreach ($settings_gateways['allowed'] as $gw => $active) { $gateways += !empty($active) ? 1 : 0; } } $gateways = $gateways > 0 ? true : false; $hidden_class = !CoursePress_MarketPress_Integration::is_active() ? 'hidden' : ''; $content = ' <div class="cp-markertpress-is-active ' . $hidden_class . '"> '; if (isset($course_id) && $course_id !== 0) { $mp_product_details = get_post_custom($course_id); } $product_id = isset($mp_product_details['mp_product_id']) ? (int) $mp_product_details['mp_product_id'][0] : false; $product_id = empty($product_id) && isset($mp_product_details['marketpress_product']) ? (int) $mp_product_details['marketpress_product'][0] : $product_id; $mp_product_id = $product_id; $product_exists = 0 != $mp_product_id ? true : false; $paid_course = !isset($paid_course) ? 'off' : $paid_course; $paid_course = !$product_exists ? 'off' : $paid_course; $paid_course = 'off' === $paid_course && isset($mp_product_details['paid_course']) ? $mp_product_details['paid_course'][0] : $paid_course; if (isset($marketpress_product) && $marketpress_product !== '') { $marketpress_product_sku = $mp_product_details['mp_sku'][0]; } else { $marketpress_product_sku = ''; } $input_state = 'off' == $paid_course ? 'disabled="disabled"' : ''; $value = !empty($mp_product_id) ? $mp_product_id : ''; $content .= ' <input type="hidden" name="meta_mp_product_id" id="mp_product_id" value="' . esc_attr($value) . '"/> '; $hidden_class = $paid_course != 'on' ? 'hidden' : ''; $content .= ' <div class="course-paid-course-details ' . $hidden_class . '"> '; $content .= ' <div class="course-sku"> <p> <input type="checkbox" name="meta_auto_sku" ' . (isset($auto_sku) && $auto_sku == 'on' ? 'checked' : '') . ' ' . $input_state . '/> ' . esc_html__('Automatically generate Stock Keeping Unit (SKU)', 'cp') . ' </p> <input type="text" name="mp_sku" id="mp_sku" placeholder="CP-000001" value="' . esc_attr(isset($marketpress_product_sku[0]) ? $marketpress_product_sku[0] : '') . '" ' . $input_state . '/> </div> '; $content .= ' <div class="course-price"> <span class="price-label ' . esc_attr($paid_course == 'on' ? 'required' : '') . '">' . esc_html__('Price', 'cp') . '</span> <input type="text" name="mp_price" id="mp_price" value="' . esc_attr(isset($mp_product_details['mp_price'][0]) ? esc_attr($mp_product_details['mp_price'][0]) : '') . '" ' . $input_state . ' /> </div> <div class="clearfix"></div> '; $mp_is_sale = isset($mp_product_details["mp_is_sale"][0]) ? $mp_product_details["mp_is_sale"][0] : 0; $content .= ' <div class="course-sale-price"> <p> <input type="checkbox" id="mp_is_sale" name="mp_is_sale" value="' . esc_attr($mp_is_sale) . '" ' . checked($mp_is_sale, '1', false) . ' ' . $input_state . ' /> ' . esc_html__('Enabled Sale Price', 'cp') . ' </p> <span class="price-label ' . esc_attr(isset($mp_product_details) && !empty($mp_product_details["mp_is_sale"]) && checked($mp_product_details["mp_is_sale"][0], '1', false) ? "required" : "") . '">' . esc_html__('Sale Price', 'cp') . '</span> <input type="text" name="mp_sale_price" id="mp_sale_price" value="' . (!empty($mp_product_details['mp_sale_price']) ? esc_attr($mp_product_details["mp_sale_price"][0]) : 0) . '" ' . $input_state . ' /> </div> <div class="clearfix"></div> '; if (current_user_can('manage_options')) { //Try to dequeue need-help script to avoid need-help popup wp_dequeue_script('mp-need-help'); $gateway_url = admin_url('edit.php?post_type=' . self::$product_ctp . '&page=marketpress&tab=gateways&cp_admin_ref=cp_course_creation_page'); if (self::get_base() === '3.0') { $gateway_url = admin_url('admin.php?page=store-settings-payments&cp_admin_ref=cp_course_creation_page'); } $content .= ' <div class="course-enable-gateways ' . esc_attr($gateways ? 'gateway-active' : 'gateway-undefined') . '"> <a href="' . esc_url_raw($gateway_url . '&TB_iframe=true&width=600&height=550') . '" class="button button-incomplete-gateways thickbox ' . esc_attr($gateways ? 'hide' : '') . '" style="' . esc_attr($gateways ? 'display:none' : '') . '">' . esc_html__('Setup Payment Gateways', 'cp') . '</a> <span class="payment-gateway-required ' . esc_attr(!$gateways && $paid_course == 'on' ? 'required' : '') . '"></span> <a href="' . esc_url_raw($gateway_url . '&TB_iframe=true&width=600&height=550') . '" class="button button-edit-gateways thickbox ' . esc_attr($gateways ? '' : 'hide') . '" style="' . esc_attr($gateways ? '' : 'display:none') . '">' . esc_html__('Edit Payment Gateways', 'cp') . '</a> </div> '; } else { $content .= '<div class="course-enable-gateways gateway-active"></div>'; } $content .= ' </div> </div> '; return $content; }
/** * Shows the course cost. * * @since 1.0.0 */ function course_cost($atts) { global $coursepress; extract(shortcode_atts(array('course_id' => in_the_loop() ? get_the_ID() : '', 'course' => false, 'label' => __('Price: ', 'cp'), 'label_tag' => 'strong', 'label_delimeter' => ': ', 'no_cost_text' => __('FREE', 'cp'), 'show_icon' => 'false', 'class' => ''), $atts, 'course_cost')); $course_id = (int) $course_id; $label = sanitize_text_field($label); $label_tag = sanitize_html_class($label_tag); $label_delimeter = sanitize_html_class($label_delimeter); $no_cost_text = sanitize_text_field($no_cost_text); $show_icon = sanitize_text_field($show_icon); $class = sanitize_html_class($class); $show_icon = 'true' == $show_icon ? true : false; // Saves some overhead by not loading the post again if we don't need to. $course = empty($course) ? new Course($course_id) : object_decode($course, 'Course'); $is_paid = get_post_meta($course_id, 'paid_course', true) == 'on' ? true : false; $content = ''; if (cp_use_woo()) { if ($is_paid) { $woo_product = get_post_meta($course_id, 'woo_product', true); $wc_product = new WC_Product($woo_product); $content .= $wc_product->get_price_html(); } else { if ($show_icon) { $content .= '<span class="mp_product_price">' . $no_cost_text . '</span>'; } else { $content .= $no_cost_text; } } } else { if ($is_paid && CoursePress::instance()->marketpress_active) { $mp_product = get_post_meta($course_id, 'marketpress_product', true); $content .= do_shortcode('[mp_product_price product_id="' . $mp_product . '" label=""]'); } else { if ($show_icon) { $content .= '<span class="mp_product_price">' . $no_cost_text . '</span>'; } else { $content .= $no_cost_text; } } } if (!empty($content)) { ob_start(); ?> <div class="course-cost course-cost-<?php echo $course_id; ?> <?php echo $class; ?> "> <?php if (!empty($label)) { ?> <<?php echo $label_tag; ?> class="label"><?php echo $label; echo $label_delimeter; ?> </<?php echo $label_tag; ?> ><?php } echo $content; ?> </div> <?php $content = ob_get_clean(); } // Return the html in the buffer. return $content; }
<p><?php _e('Students will need to enter this pass code in order to enroll.', 'cp'); ?> </p> <input type="text" name="meta_passcode" value="<?php echo esc_attr(stripslashes($passcode)); ?> "/> </div> <?php // Check to see if we're offering paid courses. if ($offer_paid) { if (cp_use_woo()) { //START WOO ?> <div class="narrow product"> <label> <?php _e('Cost to participate in this course', 'cp'); ?> </label> <div class="course-paid" id="marketpressprompt"> <input type="checkbox" name="meta_paid_course" <?php echo isset($paid_course) && $paid_course == 'on' ? 'checked' : ''; ?> id="paid_course"></input>
function virtual_page_template() { global $post, $wp_query; if (isset($post) && $post->post_type == 'virtual_page') { $theme_file = locate_template(array('page.php')); if ($theme_file != '') { include TEMPLATEPATH . "/page.php"; exit; } } if (cp_use_woo() && cp_redirect_woo_to_course()) { if (isset($post) && $post->post_type == 'product') { if (isset($post->post_parent)) { //parent course if ($post->post_parent !== 0 && get_post_type($post->post_parent) == 'course') { $course = new Course($post->post_parent); wp_redirect($course->get_permalink()); exit; } } } } else { if (isset($post) && $post->post_type == 'product' && $wp_query->is_page) { if (isset($post->post_parent)) { //parent course if ($post->post_parent !== 0 && get_post_type($post->post_parent) == 'course') { $course = new Course($post->post_parent); wp_redirect($course->get_permalink()); exit; } } } } }
function update_mp_product($course_id = false) { $course_id = $course_id ? $course_id : $this->id; $automatic_sku_number = 'CP-' . $course_id; if (cp_use_woo()) { $mp_product_id = CP_WooCommerce_Integration::woo_product_id($course_id); } else { do_action('coursepress_mp_update_product', $course_id); return true; //$mp_product_id = $this->mp_product_id( $course_id ); } $post = array('post_status' => 'publish', 'post_title' => cp_filter_content($this->details->post_title, true), 'post_type' => 'product', 'post_parent' => $course_id); // Add or Update a product if its a paid course if (isset($_POST['meta_paid_course']) && 'on' == $_POST['meta_paid_course']) { if ($mp_product_id) { $post['ID'] = $mp_product_id; //If ID is set, wp_insert_post will do the UPDATE instead of insert } $post_id = wp_insert_post($post); // Only works if the course actually has a thumbnail. set_post_thumbnail($mp_product_id, get_post_thumbnail_id($course_id)); $automatic_sku = $_POST['meta_auto_sku']; if ($automatic_sku == 'on') { $sku[0] = $automatic_sku_number; } else { $sku[0] = cp_filter_content(!empty($_POST['mp_sku']) ? $_POST['mp_sku'] : '', true); } if (cp_use_woo()) { update_post_meta($this->id, 'woo_product_id', $post_id); update_post_meta($this->id, 'woo_product', $post_id); $price = cp_filter_content(!empty($_POST['mp_price']) ? $_POST['mp_price'] : 0, true); $sale_price = cp_filter_content(!empty($_POST['mp_sale_price']) ? $_POST['mp_sale_price'] : 0, true); update_post_meta($post_id, '_virtual', 'yes'); update_post_meta($post_id, '_sold_individually', 'yes'); update_post_meta($post_id, '_sku', $sku[0]); update_post_meta($post_id, '_regular_price', $price); if (!empty($_POST['mp_is_sale'])) { update_post_meta($post_id, '_sale_price', $sale_price); update_post_meta($post_id, '_price', $sale_price); } else { update_post_meta($post_id, '_price', $price); } update_post_meta($post_id, 'mp_is_sale', cp_filter_content(!empty($_POST['mp_is_sale']) ? $_POST['mp_is_sale'] : '', true)); update_post_meta($post_id, 'cp_course_id', $this->id); } else { //update_post_meta( $this->id, 'mp_product_id', $post_id ); //update_post_meta( $this->id, 'marketpress_product', $post_id ); // //$price = cp_filter_content( (!empty( $_POST[ 'mp_price' ] ) ? $_POST[ 'mp_price' ] : 0 ), true ); //$sale_price = cp_filter_content( (!empty( $_POST[ 'mp_sale_price' ] ) ? $_POST[ 'mp_sale_price' ] : 0 ), true ); //update_post_meta( $post_id, 'mp_sku', $sku ); //update_post_meta( $post_id, 'mp_var_name', serialize( array() ) ); //update_post_meta( $post_id, 'mp_price', $price ); //update_post_meta( $post_id, 'mp_sale_price', $sale_price ); //update_post_meta( $post_id, 'mp_is_sale', cp_filter_content( (!empty( $_POST[ 'mp_is_sale' ] ) ? $_POST[ 'mp_is_sale' ] : '' ), true ) ); //update_post_meta( $post_id, 'mp_file', get_permalink( $this->id ) ); //update_post_meta( $post_id, 'cp_course_id', $this->id ); } // Remove product if its not a paid course (clean up MarketPress products) } elseif (isset($_POST['meta_paid_course']) && 'off' == $_POST['meta_paid_course']) { if ($mp_product_id && 0 != $mp_product_id) { //if ( get_post_type( $mp_product_id ) == 'product' ) { // wp_delete_post( $mp_product_id ); //} if (cp_use_woo()) { delete_post_meta($this->id, 'woo_product_id'); delete_post_meta($this->id, 'woo_product'); } else { // Don't delete these anymore... //delete_post_meta( $this->id, 'mp_product_id' ); //delete_post_meta( $this->id, 'marketpress_product' ); } } } }