Skip to content

Instantly share code, notes, and snippets.

@FranciscoHV
Forked from MrVibe/course_product.php
Created April 15, 2016 14:21
Show Gist options
  • Save FranciscoHV/c997658d1e3627ee7bd166aef4238095 to your computer and use it in GitHub Desktop.
Save FranciscoHV/c997658d1e3627ee7bd166aef4238095 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');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment