ulgm_courses_is_taxable
Filters whether a course is taxable before it's displayed in the learning management system.
add_filter( 'ulgm_courses_is_taxable', $callback, 10, 1 );
Description
Fires when determining if a course product is taxable. Developers can filter the 'taxable' argument to manually set tax status. Accepts the course product object as $this. Used within the WooCommerce integration to check product tax class.
Usage
add_filter( 'ulgm_courses_is_taxable', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - This parameter represents the initial taxable status of the course, which can be filtered to change whether the course is considered taxable.
Return Value
The filtered value.
Examples
/**
* Example of filtering the ulgm_courses_is_taxable hook to conditionally mark a course as taxable.
*
* This function checks if the course is managed by a specific user role ('course_manager')
* and if so, it prevents the course from being taxed. Otherwise, it defaults to the
* original taxable status.
*
* @param mixed $taxable The original taxable status of the course.
* @param WC_Product_Course $this The current course product object.
* @return mixed The modified taxable status.
*/
add_filter( 'ulgm_courses_is_taxable', function( $taxable, $this ) {
// Check if the current user has the 'course_manager' role.
if ( current_user_can( 'course_manager' ) ) {
// If the user is a course manager, make the course non-taxable.
return false;
}
// Otherwise, return the original taxable status.
return $taxable;
}, 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:106
public function is_taxable() {
return apply_filters( 'ulgm_courses_is_taxable', 'taxable', $this );
}