Filter uncanny-automator-pro

uap_option_all_wc_products_list

Filters the list of all WooCommerce products available for selection within the Ultimate Addons for WooCommerce plugin.

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

Description

Filters the list of all WooCommerce products before they are displayed in Uncanny Automator. Developers can use this to modify, add, or remove products from the list, influencing which products are available in triggers and actions. This hook fires when populating product data for Automator's WooCommerce integrations.


Usage

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

Parameters

$products_list (mixed)
This parameter contains the list of WooCommerce products, which can be filtered by product type.

Return Value

The filtered value.


Examples

add_filter( 'uap_option_all_wc_products_list', 'my_custom_filter_wc_products_list', 10, 1 );

/**
 * Example: Filter the list of WooCommerce products to exclude a specific product.
 *
 * This function demonstrates how to modify the list of WooCommerce products
 * that Uncanny Automator Pro provides for use in its triggers and actions.
 * In this example, we'll remove a product with a specific ID from the list.
 *
 * @param array $products_list The original list of WooCommerce products,
 *                             each item being an associative array with 'value' (product ID)
 *                             and 'text' (product title).
 * @return array The modified list of WooCommerce products.
 */
function my_custom_filter_wc_products_list( $products_list ) {
	// Define the ID of the product you want to exclude.
	$exclude_product_id = 123; // Replace with the actual product ID

	// Iterate through the product list and remove the product if its ID matches.
	foreach ( $products_list as $key => $product_data ) {
		if ( isset( $product_data['value'] ) && $product_data['value'] == $exclude_product_id ) {
			unset( $products_list[ $key ] );
			break; // Stop searching once the product is found and removed.
		}
	}

	// Re-index the array to ensure sequential keys after removal.
	return array_values( $products_list );
}

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/woocommerce/helpers/woocommerce-pro-helpers.php:602
uncanny-automator-pro/src/integrations/woocommerce-subscription/fields/order-fields.php:314

public function all_wc_products_list( $product_type = 'simple' ) {

		if ( 'subscription' === $product_type ) {

			$subscriptions = wc_get_products(
				array(
					'type'  => array( 'subscription', 'variable-subscription' ),
					'limit' => 99999,
				)
			);
			$products_list = array();
			$temp_array    = array();

			foreach ( $subscriptions as $product ) {
				$temp_array['value'] = $product->get_id();
				$temp_array['text']  = $product->get_name();
				array_push( $products_list, $temp_array );
			}
		} else {
			$product_posts = get_posts(
				array(
					'post_type'      => 'product',
					'posts_per_page' => 9999999,
					'orderby'        => 'title',
					'order'          => 'ASC',
					'post_status'    => 'publish',
				)
			);

			$products_list = array();
			foreach ( $product_posts as $product_post ) {
				$products_list[] = array(
					'value' => $product_post->ID,
					'text'  => $product_post->post_title,
				);
			}
		}

		return apply_filters( 'uap_option_all_wc_products_list', $products_list );
	}


Scroll to Top