ulgm_courses_is_sold_individually
Filters whether a course is sold individually, allowing customization of this core integration behavior.
add_filter( 'ulgm_courses_is_sold_individually', $callback, 10, 1 );
Description
This filter hook determines if a course is sold individually. Developers can use it to override the default behavior, allowing courses to be bundled or sold independently. It fires within the WooCommerce product query context.
Usage
add_filter( 'ulgm_courses_is_sold_individually', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - This parameter is a boolean value indicating whether the course is sold individually.
Return Value
The filtered value.
Examples
// Prevent a specific course from being sold individually if it has a certain tag.
add_filter( 'ulgm_courses_is_sold_individually', function( $is_sold_individually, $course_object ) {
// Check if the current course has the tag 'bundle-only'.
if ( has_term( 'bundle-only', 'product_tag', $course_object->get_id() ) ) {
// If it has the tag, disable individual sale.
return false;
}
// Otherwise, return the original value.
return $is_sold_individually;
}, 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:88
public function is_sold_individually( $context = 'view' ) {
return apply_filters( 'ulgm_courses_is_sold_individually', true, $this );
}