Filter
uncanny-automator-pro
uap_option_get_mp_products
Filters the list of products available for affiliate commissions before they are retrieved.
add_filter( 'uap_option_get_mp_products', $callback, 10, 1 );
Description
This filter allows modification of AffiliateWP products data before it's returned. Developers can use this to customize product display, filter available products, or add/remove product-specific information within Uncanny Automator Pro's AffiliateWP integration. It fires when Uncanny Automator Pro retrieves a list of AffiliateWP products for use in automations.
Usage
add_filter( 'uap_option_get_mp_products', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is likely an option code or identifier related to retrieving marketing platform products.
Return Value
The filtered value.
Examples
<?php
/**
* Filter the 'uap_option_get_mp_products' hook to exclude products that are not for sale.
*
* This example demonstrates how to modify the list of products returned by the Uncanny Automator Pro
* AffiliateWP integration. It checks each product and removes any that have a meta key indicating
* they are not currently available for purchase.
*
* @param array $option The array of product data being filtered.
* @return array The modified array of product data, with unavailable products removed.
*/
add_filter( 'uap_option_get_mp_products', function( $option ) {
// Ensure $option is an array before proceeding.
if ( ! is_array( $option ) ) {
return $option;
}
$available_products = [];
foreach ( $option as $product_id => $product_data ) {
// Assuming 'is_for_sale' is a custom meta key you might use to control product availability.
// You would replace this with the actual meta key used by your setup or affiliate plugin.
$is_for_sale = get_post_meta( $product_id, '_your_custom_product_for_sale_meta_key', true );
// If the product is marked as for sale (or the meta key doesn't exist, meaning it's available by default)
if ( $is_for_sale === 'yes' || empty( $is_for_sale ) ) {
$available_products[ $product_id ] = $product_data;
}
}
// Return the filtered array of products.
return $available_products;
}, 10, 1 );
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:111
public function get_mp_products( $label = null, $option_code = 'MPPRODUCTS', $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' => 'memberpressproduct',
'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_mp_products', $option );
}