Skip to content

Instantly share code, notes, and snippets.

@adeel-raza
Last active July 11, 2019 03:26
Show Gist options
  • Save adeel-raza/93460ddedf818a4775919c9e64c184c7 to your computer and use it in GitHub Desktop.
Save adeel-raza/93460ddedf818a4775919c9e64c184c7 to your computer and use it in GitHub Desktop.
Show content based on LearnDash course type
// Show content conditionally based on course type
add_shortcode( 'ld_display_course_content', 'ld_shortcode_display_course_content' );
function ld_shortcode_display_course_content( $atts , $content = null ) {
global $post;
if( is_admin() || !$post || !$post->post_type == 'sfwd-courses' || !isset( $atts['course_type'] ) ) {
return;
}
$course_meta = get_post_meta($post->ID, '_sfwd-courses', true);
if($course_meta['sfwd-courses_course_price_type'] == $atts['course_type']) {
return $content;
} else {
return;
}
}
@adeel-raza
Copy link
Author

Add this function at the end of your theme's functions.php file and use the shortcode on your course page as below
[ld_display_course_content course_type="closed"]my content on closed course type[/ld_display_course_content]

You can change the course_type value to show content on your choice of LearnDash course type

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