ulgm_courses_is_downloadable
Filters whether a lesson or course is downloadable, allowing customization of download availability.
add_filter( 'ulgm_courses_is_downloadable', $callback, 10, 2 );
Description
Fires when determining if a course product is downloadable. Developers can use this filter to override the default downloadable status of a course product. The `$this` parameter represents the course product object.
Usage
add_filter( 'ulgm_courses_is_downloadable', 'your_function_name', 10, 2 );
Parameters
-
$this(mixed) - This parameter contains the downloadable status of the course, typically a boolean value.
-
$this(mixed) - This parameter contains the downloadable status of the course, which is the value being filtered.
Return Value
The filtered value.
Examples
add_filter( 'ulgm_courses_is_downloadable', 'my_custom_course_downloadable_logic', 10, 2 );
/**
* Conditionally makes a course downloadable based on user role.
*
* @param bool $is_downloadable The current downloadable status of the course.
* @param object $course_object The course product object.
* @return bool The modified downloadable status.
*/
function my_custom_course_downloadable_logic( $is_downloadable, $course_object ) {
// Get the current logged-in user.
$user = wp_get_current_user();
// Check if the user is logged in and has the 'premium_member' role.
if ( is_user_logged_in() && in_array( 'premium_member', (array) $user->roles ) ) {
// If they are a premium member, always make the course downloadable.
return true;
}
// Otherwise, return the original downloadable status.
return $is_downloadable;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/includes/woocommerce/wc_product_courses.php:76
public function is_downloadable( $context = 'view' ) {
return apply_filters( 'ulgm_courses_is_downloadable', $this->get_prop( 'downloadable', $context ), $this );
}