ulgm_courses_is_virtual
Filters whether a LearnDash course is considered virtual before displaying course content.
add_filter( 'ulgm_courses_is_virtual', $callback, 10, 2 );
Description
Filters whether a LearnPress course is considered virtual. Developers can use this hook to programmatically determine if a course is virtual, affecting shipping calculations and other virtual-specific logic within LearnPress. It fires when checking the virtual status of a course.
Usage
add_filter( 'ulgm_courses_is_virtual', 'your_function_name', 10, 2 );
Parameters
-
$this(mixed) - This parameter contains the value of the 'virtual' property of the course product.
-
$this(mixed) - This parameter contains the virtual property of the course object.
Return Value
The filtered value.
Examples
/**
* Example of using the 'ulgm_courses_is_virtual' filter hook.
*
* This example demonstrates how to modify the virtual status of a course.
* It checks if the course is a specific type ('special_course_type') and,
* if so, overrides its virtual status to true, regardless of its actual setting.
*
* @param bool $is_virtual The current virtual status of the course.
* @param WC_Product_Course $course_object The WC_Product_Course object being filtered.
* @return bool The modified virtual status.
*/
function my_custom_ulgm_course_virtual_status( $is_virtual, $course_object ) {
// Check if the course is a specific type that we want to force as virtual.
// Replace 'special_course_type' with your actual custom course type if applicable.
// This assumes you have a way to identify your special course types,
// e.g., via a custom product meta field or by checking product type.
if ( $course_object instanceof WC_Product_Course && $course_object->get_type() === 'course' ) {
// Example: Check for a custom meta key indicating it's a "live session" course.
// You would replace 'is_live_session' with your actual meta key.
if ( get_post_meta( $course_object->get_id(), '_is_live_session', true ) === 'yes' ) {
return true; // Force this type of course to be considered virtual.
}
}
// If it's not our special type, return the original virtual status.
return $is_virtual;
}
add_filter( 'ulgm_courses_is_virtual', 'my_custom_ulgm_course_virtual_status', 10, 2 );
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:63
public function is_virtual( $context = 'view' ) {
return apply_filters( 'ulgm_courses_is_virtual', $this->get_prop( 'virtual', $context ), $this );
}