Last active
November 17, 2022 14:36
-
-
Save danielmcclure/439b6f4b85fb626daecb158d70185b40 to your computer and use it in GitHub Desktop.
Add LearnDash Enrolled Courses Grid to My Account Tab in WooCommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Add LearnDash Enrolled Courses Grid to My Account Tab in WooCommerce */ | |
/* Add Courses Link to My Account menu */ | |
add_filter ( 'woocommerce_account_menu_items', 'wc_ld_link', 40 ); | |
function wc_ld_link( $menu_links ){ | |
$menu_links = array_slice( $menu_links, 0, 5, true ) | |
+ array( 'courses' => 'My Courses' ) | |
+ array_slice( $menu_links, 5, NULL, true ); | |
return $menu_links; | |
} | |
/* Add Courses Permalink Endpoint */ | |
add_action( 'init', 'wc_ld_endpoint' ); | |
function wc_ld_endpoint() { | |
add_rewrite_endpoint( 'courses', EP_PAGES ); | |
} | |
/* Add Content to Endpoint */ | |
add_action( 'woocommerce_account_courses_endpoint', 'learndash_my_account_endpoint_content' ); | |
function learndash_my_account_endpoint_content() { | |
// Add Course Grid Scripts & Styles | |
wp_enqueue_style( 'learndash_course_grid_css', plugins_url( 'learndash-course-grid/assets/css/style.css' ) ); | |
wp_enqueue_script( 'learndash_course_grid_js', plugins_url( 'learndash-course-grid/assets/js/script.js' ), array('jquery' ) ); | |
wp_enqueue_style( 'ld-cga-bootstrap', plugins_url( 'learndash-course-grid/assets/css/bootstrap.css' ) ); | |
// LearnDash Course Grid | |
echo do_shortcode( '[ld_course_list mycourses="true" progress_bar="true"]' ); | |
} | |
/* NOTE: You will need to re-save your permalinks to activate this functionality */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment