Filter uncanny-automator-pro

uap_option_woocommerce_order_item_trigger_conditions

Filters the conditions available for triggering actions based on WooCommerce order items, allowing customization of the available options.

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

Description

Allows developers to modify the options array for WooCommerce order item trigger conditions in Uncanny Automator. This filter hooks in when building the configuration for a trigger based on WooCommerce order items, enabling customization of available conditions, labels, or input types.


Usage

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

Parameters

$options (mixed)
This parameter is an array containing configuration options for a WooCommerce order item trigger condition, including its code, display label, and input type.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the 'uap_option_woocommerce_order_item_trigger_conditions' hook.
 * This example adds a new custom trigger condition to the WooCommerce order item trigger options.
 *
 * @param array $options The current array of trigger condition options.
 * @return array The modified array of trigger condition options.
 */
add_filter( 'uap_option_woocommerce_order_item_trigger_conditions', 'my_custom_woocommerce_order_item_trigger_conditions', 10, 1 );

function my_custom_woocommerce_order_item_trigger_conditions( $options ) {

	// Check if the existing options array is valid and has an 'options' key.
	if ( is_array( $options ) && isset( $options['options'] ) && is_array( $options['options'] ) ) {

		// Define the new custom trigger condition.
		$new_trigger_condition = array(
			'value' => 'order_item_custom_status', // A unique value for this trigger.
			'label' => esc_html__( 'Order item has a custom status', 'your-text-domain' ), // The user-facing label.
		);

		// Add the new condition to the existing options.
		$options['options']['order_item_custom_status'] = $new_trigger_condition;

		// You could also potentially modify existing options if needed, for example:
		// if ( isset( $options['options']['product_purchased'] ) ) {
		//     $options['options']['product_purchased']['label'] = esc_html__( 'A specific product was bought', 'your-text-domain' );
		// }

	} elseif ( is_array( $options ) && ! isset( $options['options'] ) ) {
		// If the structure is unexpected but it's an array, we might need to initialize it.
		// This is less likely if the hook is correctly implemented by the plugin.
		$options['options'] = array(
			'order_item_custom_status' => array(
				'value' => 'order_item_custom_status',
				'label' => esc_html__( 'Order item has a custom status', 'your-text-domain' ),
			),
		);
	}

	// Always return the modified (or unmodified) $options array.
	return $options;
}
?>

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

public function get_woocommerce_order_item_trigger_conditions( $code = 'TRIGGERCOND' ) {
		$options = array(
			'option_code' => $code,
			/* translators: Noun */
			'label'       => esc_html_x( 'Trigger condition', 'Woocommerce', 'uncanny-automator-pro' ),
			'input_type'  => 'select',
			'required'    => true,
			'options'     => $this->get_order_item_trigger_condition_labels(),
		);

		return apply_filters( 'uap_option_woocommerce_order_item_trigger_conditions', $options );
	}


Scroll to Top