Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 99manish/a4b13d00fe6a16c10760ed36279b10ed to your computer and use it in GitHub Desktop.
Save 99manish/a4b13d00fe6a16c10760ed36279b10ed to your computer and use it in GitHub Desktop.
hide create product front end and auto set pricing
add_action('wplms_course_creation_tabs',function ($settings){
if(current_user_can('manage_options'))
return $settings;
foreach ($settings['course_pricing']['fields'] as $key => $setting) {
if($setting['id']=='vibe_product'){
unset($settings['course_pricing']['fields'][$key]);
break;
}
}
return $settings;
},999999,1);
add_action('wplms_front_end_save_course_pricing',function ($course_id,$settings=null){
$price = 5;//CHANGE THE PRICE VALUE HERE
$count = 0;
if(!empty($settings)){
foreach ($settings as $key => $setting) {
if($setting->id=='vibe_product'){
if(empty($setting->value)){
create_course_product($course_id,$price);
}
$count++;
}
}
if($count <= 0){
create_course_product($course_id,$price);
}
}
},10,2);
function create_course_product($course_id,$price){
$the_course = get_post($course_id);
$product_settings = array(
'post_status' => 'publish',
'post_type' => 'product',
'post_title' => $the_course->post_title,
'post_excerpt' => $the_course->post_excerpt,
'post_content' => $the_course->post_content,
'comment_status' => 'open'
);
$product_settings = apply_filters('wplms_frontend_new_product',$product_settings);
$product_id = wp_insert_post($product_settings);
if(isset($product_id) && $product_id){
$attach_id = get_post_meta($course_id, "_thumbnail_id", true);
add_post_meta($product_id, '_thumbnail_id', $attach_id);
wp_set_object_terms($product_id, 'simple', 'product_type');
update_post_meta($product_id,'_price',$price);
update_post_meta($product_id,'_regular_price',$price);
update_post_meta($product_id,'_visibility','visible');
update_post_meta($product_id,'_virtual','yes');
update_post_meta($product_id,'_downloadable','yes');
update_post_meta($product_id,'_sold_individually','yes');
$courses = array($course_id);
update_post_meta($product_id,'vibe_courses',$courses);
update_post_meta($course_id,'vibe_product',$product_id);
$thumbnail_id = get_post_thumbnail_id($course_id);
set_post_thumbnail($product_id,$thumbnail_id);
/*if($vibe_subscription == 'S'){
update_post_meta($product_id,'vibe_subscription','S');
update_post_meta($product_id,'vibe_duration',$vibe_duration);
}*/
do_action('wplms_course_pricing_product_added',$course_id,$product_id);
//Linkage
$linkage = vibe_get_option('linkage');
if(isset($linkage) && $linkage){
$course_linkage=wp_get_post_terms( $course_id, 'linkage',array("fields" => "names"));
if(isset($course_linkage) && is_array($course_linkage))
wp_set_post_terms( $product_id, $course_linkage, 'linkage' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment