Filter Uncanny Redemption Codes

ulc_automator_codes_is_downloadable

Filters whether a download should be considered downloadable.

add_filter( 'ulc_automator_codes_is_downloadable', $callback, 10, 2 );

Description

Filters whether a product automator code is downloadable. This hook allows developers to programmatically control downloadability based on custom logic before the product is displayed. It passes the current downloadability status and the automator code object.


Usage

add_filter( 'ulc_automator_codes_is_downloadable', 'your_function_name', 10, 2 );

Parameters

$this (mixed)
This parameter contains the current downloadable status of the automator code.
$this (mixed)
This parameter contains the downloadable status of the automator code, potentially influenced by the provided context.

Return Value

The filtered value.


Examples

/**
 * Example filter to modify the downloadable status of an automator code based on user role.
 *
 * If the current user is an 'editor', we'll make the automator code not downloadable
 * for them, regardless of its default setting.
 *
 * @param bool   $is_downloadable The current downloadable status.
 * @param object $automator_code  The automator code object instance.
 * @return bool The modified downloadable status.
 */
add_filter(
	'ulc_automator_codes_is_downloadable',
	function ( $is_downloadable, $automator_code ) {
		// Check if the current user has the 'editor' role.
		if ( current_user_can( 'editor' ) ) {
			// If they are an editor, force it to be not downloadable for them.
			return false;
		}

		// Otherwise, return the original downloadable status.
		return $is_downloadable;
	},
	10, // Priority
	2   // Accepted arguments: $is_downloadable, $automator_code
);

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:89

public function is_downloadable( $context = 'view' ) {
		return apply_filters( 'ulc_automator_codes_is_downloadable', $this->get_prop( 'downloadable', $context ), $this );
	}


Scroll to Top