ulgm_license_is_virtual
Filters whether a license is considered virtual, allowing for custom logic before a license is displayed or processed.
add_filter( 'ulgm_license_is_virtual', $callback, 10, 2 );
Description
Fires to determine if a license is virtual. Developers can use this filter to override the default virtual status for licenses, for example, to treat physically shipped licenses as non-virtual. The first parameter is the current virtual status, and the second is the license object itself.
Usage
add_filter( 'ulgm_license_is_virtual', 'your_function_name', 10, 2 );
Parameters
-
$this(mixed) - This parameter contains the current virtual status of the product license, which is retrieved from the product's properties.
-
$this(mixed) - The `$this` parameter refers to the current `WC_Product_License` object being checked.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the 'ulgm_license_is_virtual' hook.
* This example checks if a license product is considered virtual,
* and if it's being viewed in a specific context, it overrides the
* default virtual status to false.
*
* @param bool $is_virtual The current virtual status of the license.
* @param WC_Product_License $license The WC_Product_License object being filtered.
* @return bool The modified virtual status.
*/
add_filter( 'ulgm_license_is_virtual', function( $is_virtual, $license ) {
// We want to treat licenses associated with the 'admin_view' context as non-virtual for this specific scenario.
// This might be useful if you have a backend view where you don't want to enforce virtual product rules.
if ( 'admin_view' === $license->get_prop( 'context' ) ) {
return false;
}
// Otherwise, return the original virtual status.
return $is_virtual;
}, 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_license.php:64
src/classes/woocommerce/woocommerce-buy-courses.php:336
public function is_virtual( $context = 'view' ) {
return apply_filters( 'ulgm_license_is_virtual', $this->get_prop( 'virtual', $context ), $this );
}