Created
November 28, 2023 19:16
-
-
Save Lonsdale201/0e23048f1ff1597087e1a396bd41a66b to your computer and use it in GitHub Desktop.
JetEngine - Custom Macro - Learndash - Current user all purchased courses
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
// place the code in the child theme functions.php or a custom code snippets plugin. | |
// how to use | |
// Create a new Post Query in the Query builder. Select the post type: Course | |
// Go to the Meta Query section | |
// click the Add new button | |
// in the VALUE field choose the Dynamic tag icon, and select LD User Courses Access | |
// In the operator field select the "in the list" option | |
// HELP IMAGE : https://prnt.sc/3g_INGSx_yNb | |
// DONE | |
// note: Dont forget the admin default have access all available course | |
// My all Gist: https://gist.github.com/Lonsdale201 | |
add_action( 'jet-engine/register-macros', function() { | |
class LD_User_Courses_Access extends \Jet_Engine_Base_Macros { | |
public function macros_tag() { | |
return 'ld_user_courses_access'; | |
} | |
public function macros_name() { | |
return 'LD User Courses Access'; | |
} | |
public function macros_args() { | |
return array(); | |
} | |
public function macros_callback( $args = array() ) { | |
$user_id = get_current_user_id(); | |
if ( !$user_id ) { | |
return 'User is not logged in'; | |
} | |
$courses = ld_get_mycourses($user_id); | |
if ( empty($courses) ) { | |
return 'User has no course access'; | |
} | |
return implode( ',', $courses ); | |
} | |
} | |
new LD_User_Courses_Access(); | |
} ); |
Hey, I did it but it didn't work, do you know if something changed?
Thanks for letting me know, I already have a newer version, I just forgot to replace it. Nevertheless, I can recommend my plugin which includes more among this and other Leardash + jetengine features:
https://github.com/Lonsdale201/dynamic-elementor-extension
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I did it but it didn't work, do you know if something changed?
