Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Created March 24, 2015 13:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MrVibe/5798dafae9c4a9219204 to your computer and use it in GitHub Desktop.
Save MrVibe/5798dafae9c4a9219204 to your computer and use it in GitHub Desktop.
Course product shortcode
/*-----------------------------------------------------------------------------------*/
/* Course Product
/*
/* USAGE : xx is course id
/* [course_product id="xx" details="price"]
/* [course_product id="xx" details="sku"]
/* [course_product id="xx" details="sales"]
/* [course_product id="xx" details="note"]
/* Above shortcode can also be used on certificate pages and remove the id field:
/* [course_product details="sku"] , this will display SKU code of Product on certificate
/*
/*-----------------------------------------------------------------------------------*/
if (!function_exists('vibe_course_product_details')) {
function vibe_course_product_details( $atts, $content = null ) {
extract(shortcode_atts(array(
'id' => '',
'details' => '',
), $atts));
if(isset($id) && is_numeric($id)){
$course_id = $id;
}else{
if(isset($_GET['c']) && is_numeric($_GET['c']))
$course_id=$_GET['c']; // For certificate use
else
return;
}
if(get_post_type($course_id) == BP_COURSE_CPT){
$product_id = get_post_meta($course_id,'vibe_product',true);
if(isset($product_id) && is_numeric($product_id)){
switch($details){
case 'sku':
$return = get_post_meta($product_id,'_sku',true);
break;
case 'price':
$product = wc_get_product( $product_id );
$return = $product->get_price_html();
break;
case 'sales':
$return = get_post_meta($product_id,'total_sales',true);
break;
case 'note':
$return = get_post_meta($product_id,'_purchase_note',true);
break;
}
}
}
return $return;
}
add_shortcode('course_product', 'vibe_course_product_details');
}
@FranciscoHV
Copy link

a query, I am placing a timer that takes the id of the product, I need to deploy it on course details, but when calling the id that point, I throw the id of the course, but I can't call the product ID, I will serve this code for create the link between course associated with the product?

and where would you put this code in the wplms-customizer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment