Filter uncanny-automator

uap_option_advanced_coupons_all_conditions

Filters the available conditions for advanced coupons, allowing customization of coupon application rules.

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

Description

Filters the complete set of conditions available for Advanced Coupons. Developers can use this hook to dynamically add, remove, or modify coupon conditions, allowing for custom coupon logic and integrations. This hook fires when the conditions array is being constructed for Advanced Coupons.


Usage

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

Parameters

$option (mixed)
This parameter contains the value of the advanced coupon option being filtered.

Return Value

The filtered value.


Examples

<?php
/**
 * Example function to modify the conditions available for Advanced Coupons in UAP.
 *
 * This function demonstrates how to add a custom condition to the list of available
 * conditions when configuring Advanced Coupons within the Ultimate Affiliate Program (UAP) plugin.
 *
 * @param array $option The current array of options for the conditions dropdown.
 * @return array The modified array of options, including the custom condition.
 */
add_filter( 'uap_option_advanced_coupons_all_conditions', function( $option ) {

	// Check if the $option array is structured as expected and has an 'options' key.
	if ( is_array( $option ) && isset( $option['options'] ) && is_array( $option['options'] ) ) {

		// Define our custom condition.
		$custom_condition_key = 'custom_user_role';
		$custom_condition_label = __( 'User Role', 'your-text-domain' );

		// Add the custom condition to the existing options.
		// We'll place it at the beginning for visibility.
		$option['options'] = array(
			$custom_condition_key => $custom_condition_label,
		) + $option['options'];

		// Optionally, you could also add logic to 'relevant_tokens' if your custom
		// condition requires specific tokens to be available. For this example,
		// we'll leave it empty.
		// $option['relevant_tokens'] = array_merge( $option['relevant_tokens'], array( 'user_role' ) );

	}

	// Always return the modified (or original, if not modified) $option array.
	return $option;

}, 10, 1 ); // Priority 10, 1 accepted argument.

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/advanced-coupons/helpers/advanced-coupons-helpers.php:138

public function get_options_for_credit( $label = null, $option_code = 'PPCONDITION', $args = array() ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Select condition', 'uncanny-automator' );
		}

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_attr__( 'Any condition', 'uncanny-automator' ),
			)
		);

		$options = array();

		if ( $args['uo_include_any'] ) {
			$options['-1'] = $args['uo_any_label'];
		}

		$options['EQ']     = esc_html__( 'equal to', 'uncanny-automator' );
		$options['NOT_EQ'] = esc_html__( 'not equal to', 'uncanny-automator' );
		$options['LT']     = esc_html__( 'less than', 'uncanny-automator' );
		$options['GT']     = esc_html__( 'greater than', 'uncanny-automator' );
		$options['GT_EQ']  = esc_html__( 'greater or equal to', 'uncanny-automator' );
		$options['LT_EQ']  = esc_html__( 'less or equal to', 'uncanny-automator' );

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $options,
			'relevant_tokens' => array(),
		);

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

Scroll to Top