Filter uncanny-automator-pro

uap_option_get_edd_products

Filters the list of products fetched from Easy Digital Downloads for affiliate commissions.

add_filter( 'uap_option_get_edd_products', $callback, 10, 1 );

Description

Filters the list of EDD products available for integration with AffiliateWP. Developers can use this hook to modify or add to the product options presented within Uncanny Automator recipes, enabling custom product selections or excluding specific products from appearing.


Usage

add_filter( 'uap_option_get_edd_products', 'your_function_name', 10, 1 );

Parameters

$option (mixed)
This parameter represents the option or value that is being filtered and can be modified.

Return Value

The filtered value.


Examples

add_filter( 'uap_option_get_edd_products', 'my_custom_uap_edd_products_filter', 10, 1 );

/**
 * Custom filter to modify the options returned for EDD products in Uncanny Automator Pro.
 * This example filters out products that have a specific tag (e.g., "exclude-from-automator").
 *
 * @param array $option The array of EDD product options, potentially including metadata.
 * @return array The modified array of EDD product options.
 */
function my_custom_uap_edd_products_filter( $option ) {
	// Check if the EDD products are actually present in the $option array and if it's an array.
	if ( ! is_array( $option ) || ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
		return $option; // Return original if data structure is unexpected.
	}

	$filtered_options = array();
	$exclude_tag      = 'exclude-from-automator'; // Define the tag to exclude products by.

	foreach ( $option['options'] as $product_id => $product_data ) {
		// Ensure $product_data is an array and has product ID.
		if ( ! is_array( $product_data ) || ! isset( $product_data['value'] ) ) {
			$filtered_options[ $product_id ] = $product_data; // Keep unexpected data as is.
			continue;
		}

		// Fetch the product's tags to check for the exclusion tag.
		// We'll assume $product_data might contain 'meta' which could hold 'tags'.
		// In a real-world scenario, you might need to use EDD's functions to get product details if not directly available.
		$product_tags = array();
		if ( isset( $product_data['meta']['tags'] ) && is_array( $product_data['meta']['tags'] ) ) {
			$product_tags = $product_data['meta']['tags'];
		}

		// Check if the product has the exclusion tag.
		if ( ! in_array( $exclude_tag, $product_tags ) ) {
			$filtered_options[ $product_id ] = $product_data; // Add to filtered list if not excluded.
		}
	}

	// Update the 'options' key in the original $option array.
	$option['options'] = $filtered_options;

	return $option;
}

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

uncanny-automator-pro/src/integrations/affiliate-wp/helpers/affwp-pro-helpers.php:154

public function get_edd_products( $label = null, $option_code = 'EDDPRODUCTS', $args = array() ) {
		if ( ! $label ) {
			$label = __( 'Product', 'uncanny-automator-pro' );
		}

		$token        = key_exists( 'token', $args ) ? $args['token'] : false;
		$is_ajax      = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
		$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
		$end_point    = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
		$any_option   = key_exists( 'any_option', $args ) ? $args['any_option'] : false;

		$args = array(
			'post_type'      => 'download',
			'posts_per_page' => 999,
			'post_status'    => 'publish',
		);

		$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any product', 'uncanny-automator' ) );

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'supports_tokens' => $token,
			'is_ajax'         => $is_ajax,
			'fill_values_in'  => $target_field,
			'endpoint'        => $end_point,
			'options'         => $options,
		);

		return apply_filters( 'uap_option_get_edd_products', $option );
	}

Scroll to Top