ulc_automator_codes_is_virtual
Filters if a code is considered virtual when the automator is checking it.
add_filter( 'ulc_automator_codes_is_virtual', $callback, 10, 2 );
Description
Fires when checking if a product is virtual. Developers can use this filter to programmatically determine if a product should be treated as virtual, overriding the default behavior. Pass `true` to force virtual or `false` to force non-virtual.
Usage
add_filter( 'ulc_automator_codes_is_virtual', 'your_function_name', 10, 2 );
Parameters
-
$this(mixed) - This parameter represents the current virtual status of the product automator code being filtered.
-
$this(mixed) - This parameter holds the virtual status of the automator code, which can be 'yes' or 'no'.
Return Value
The filtered value.
Examples
/**
* Prevent virtual product status from being checked for automator codes.
*
* Sometimes, for specific automator code functionalities, we might want to
* bypass the default virtual product check, for example, if the automator
* code itself represents a digital delivery that shouldn't be tied to
* the product's virtual status.
*
* @param bool $is_virtual The current virtual status of the product.
* @param WC_Product $product The product object.
* @return bool Always returns false, effectively disabling the virtual check.
*/
add_filter( 'ulc_automator_codes_is_virtual', function( $is_virtual, $product ) {
// For the purpose of automator codes, we might want to treat all of them
// as non-virtual, regardless of the product's actual setting.
// This could be useful if the automator code itself represents a
// digital asset or a service that isn't directly tied to the product's
// physical or virtual shipping status.
return false;
}, 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/wc_product_automator_codes.php:76
public function is_virtual( $context = 'view' ) {
return apply_filters( 'ulc_automator_codes_is_virtual', $this->get_prop( 'virtual', $context ), $this );
}