</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> <span><?php _e('This is a Paid Course', 'cp'); ?> </span> </div> <div> <?php $woo_product_id = CP_WooCommerce_Integration::woo_product_id($course_id); $product_exists = 0 != $woo_product_id ? true : false; $paid_course = !isset($paid_course) || $paid_course == 'off' ? 'off' : 'on'; $paid_course = !$product_exists ? 'off' : $paid_course; if (isset($course_id) && $course_id !== 0) { $woo_product_details = get_post_custom($woo_product_id); //$course_id } if (isset($woo_product) && $woo_product !== '') { $woo_product_sku = get_post_meta($woo_product, '_sku', true); } else { $woo_product_sku = ''; } $input_state = 'off' == $paid_course ? 'disabled="disabled"' : ''; ?>
function woo_signup_pre_redirect_to_cart($args = array()) { $course_id = 0; if (!empty($args)) { $course_id = isset($args['course_id']) ? $args['course_id'] : false; } else { $course_id = !empty($_POST['course_id']) ? (int) $_POST['course_id'] : false; } $course = new Course($course_id); $product_id = $course->mp_product_id(); CP_WooCommerce_Integration::add_product_to_cart($product_id); }
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' ); } } } }