Filter uncanny-automator

uap_option_woocommerce_trigger_conditions

Filters WooCommerce trigger conditions, allowing customization of when specific actions are activated within the integration.

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

Description

Filters the options array for WooCommerce trigger conditions. Developers can modify or add to the available trigger condition labels and settings. This hook fires when preparing the options for WooCommerce trigger condition selection.


Usage

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

Parameters

$options (mixed)
This parameter is a mixed type array that contains options related to trigger conditions.

Return Value

The filtered value.


Examples

<?php
/**
 * Example function to modify WooCommerce trigger conditions for Uncanny Automator Pro.
 * This function might be used to dynamically add or remove specific trigger conditions
 * based on certain criteria, or to adjust the labels of existing conditions.
 *
 * @param array $options The current options for the trigger condition dropdown.
 * @return array The modified options array.
 */
add_filter( 'uap_option_woocommerce_trigger_conditions', 'my_custom_woocommerce_trigger_conditions', 10, 1 );

function my_custom_woocommerce_trigger_conditions( $options ) {
	// Example: Let's say we want to conditionally remove the 'product_purchased'
	// trigger condition if a specific WooCommerce setting is disabled.

	// First, retrieve the existing trigger condition labels.
	// In a real scenario, you might need to call a method similar to
	// $this->get_trigger_condition_labels() if this function were within a class.
	// For this standalone example, we'll simulate having these labels.

	// Simulating the output of $this->get_trigger_condition_labels()
	$default_conditions = array(
		'any_product_purchased' => __( 'Any product purchased', 'uncanny-automator' ),
		'specific_product_purchased' => __( 'A specific product purchased', 'uncanny-automator' ),
		'product_category_purchased' => __( 'A product from a specific category purchased', 'uncanny-automator' ),
		'order_status_changed' => __( 'Order status changed to', 'uncanny-automator' ),
		'coupon_used' => __( 'Coupon used on order', 'uncanny-automator' ),
		// ... other potential conditions
	);

	// Ensure the options array is in the expected format for modification.
	// The original hook likely expects an array where keys are condition IDs and values are labels.
	// If $options is not already in this format, you might need to adjust.
	// For this example, we'll assume $options is the array of trigger condition labels.

	// Retrieve a hypothetical WooCommerce setting. Replace this with actual WooCommerce API calls.
	$is_new_product_triggers_enabled = get_option( 'my_custom_wc_enable_new_product_triggers', true );

	if ( ! $is_new_product_triggers_enabled ) {
		// If the setting is disabled, remove the 'specific_product_purchased' condition.
		if ( isset( $options['specific_product_purchased'] ) ) {
			unset( $options['specific_product_purchased'] );
		}
	}

	// You could also add new conditions here if needed.
	// $options['my_new_custom_condition'] = __( 'My Custom Trigger Condition', 'uncanny-automator' );

	// The filter expects the modified $options array to be returned.
	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

src/integrations/woocommerce/helpers/woocommerce-helpers.php:272
uncanny-automator-pro/src/integrations/woocommerce/helpers/woocommerce-pro-helpers.php:996

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

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


Scroll to Top