<?php
/**
 * BricksExtras Conditions
 *
 * Handles dynamic conditions for Bricks elements.
 *
 * @package BricksExtras
 */

namespace BricksExtras;

use Bricks\Query;
use DateTimeImmutable;
use EDD_recurring_subscriber;
use SureMembers\Inc\Access_Groups;
use TRP_Translate_Press;
use WC_Product;
use WC_Product_Factory;
use WP_Query;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( class_exists( 'BricksExtrasConditions' ) ) {
	return;
}

if ( ! class_exists( 'BricksExtrasHelpers' ) ) {
	require_once 'BricksExtrasHelpers.php';
}

/**
 * BricksExtras Conditions Class
 *
 * Provides dynamic conditions functionality for Bricks elements.
 */
class BricksExtrasConditions {

	/**
	 * Prefix for options and settings.
	 *
	 * @var string
	 */
	public static string $prefix = '';

	/**
	 * Initialize the conditions functionality.
	 *
	 * @param string $prefix The prefix for options and settings.
	 */
	public static function init( $prefix ): void {

		self::$prefix = $prefix;

		add_filter( 'bricks/conditions/groups', array( __CLASS__, 'condition_group' ) );
		add_filter( 'bricks/conditions/options', array( __CLASS__, 'condition_options' ) );
		add_filter( 'bricks/conditions/result', array( __CLASS__, 'run_conditions' ), 10, 3 );
	}


	/**
	 * Add condition groups to Bricks.
	 *
	 * @param array $groups Existing condition groups.
	 * @return array Modified condition groups.
	 */
	public static function condition_group( array $groups ): array {

		// Prefix names with x_.

		/* More general conditions. */

		$general_conditions_array  = Helpers::get_extras_conditions( 'general' );
		$general_conditions_active = false;

		foreach ( $general_conditions_array as $key => $condition ) {

			if ( 1 === intval( get_option( self::$prefix . $key, 0 ) ) ) {
				$general_conditions_active = true;
				break;
			}
		}

		if ( $general_conditions_active ) {
			$groups[] = array(
				'name'  => 'x_extras_conditions',
				'label' => 'Extras',
			);
		}

		/* member conditions */

		$member_conditions_array  = Helpers::get_extras_conditions( 'member' );
		$member_conditions_active = false;

		foreach ( $member_conditions_array as $key => $condition ) {
			if ( 1 === intval( get_option( self::$prefix . $key, 0 ) ) ) {
				$member_conditions_active = true;
				break;
			}
		}

		if ( $member_conditions_active ) {
			$groups[] = array(
				'name'  => 'x_member_conditions',
				'label' => esc_html__( 'Member Conditions', 'bricksextras' ) . ' (extras)',
			);
		}

		/* WooCommerce conditions */

		$wc_conditions_array  = Helpers::get_extras_conditions( 'wc' );
		$wc_conditions_active = false;

		foreach ( $wc_conditions_array as $key => $condition ) {
			if ( 1 === intval( get_option( self::$prefix . $key, 0 ) ) ) {
				$wc_conditions_active = true;
				break;
			}
		}

		if ( $wc_conditions_active ) {
			$groups[] = array(
				'name'  => 'x_wc_conditions',
				'label' => sprintf(
					// translators: %s is the plugin name (e.g., WooCommerce).
					esc_html__( '%s Conditions', 'bricksextras' ),
					'WooCommerce'
				) . ' (extras)',
			);
		}

		return $groups;
	}


	/**
	 * Add condition options to Bricks.
	 *
	 * @param array $options Existing condition options.
	 * @return array Modified condition options.
	 */
	public static function condition_options( array $options ): array {

		// Prefix keys with x_.

		/* MemberPress. */

		if ( get_option( self::$prefix . 'memberpress' ) && class_exists( '\MeprSubscription' ) ) {

			$options[] = array(
				'key'     => 'x_memberpress_membership',
				'label'   => esc_html__( 'User membership', 'bricksextras' ) . ' (MemberPress)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'Active', 'bricks' ),
						'!=' => esc_html__( 'Inactive', 'bricks' ),
					),
					'placeholder' => esc_html__( 'Active', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'memberpressproduct' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_memberpress_membership_id',
				'label'   => esc_html__( 'User membership ID', 'bricksextras' ) . ' (MemberPress)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'Active', 'bricks' ),
						'!=' => esc_html__( 'Inactive', 'bricks' ),
					),
					'placeholder' => esc_html__( 'Active', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					// translators: %s is the type of value to provide (e.g., ID).
					'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
				),
			);

		}

		/* Easy Digital Downloads. */

		if ( get_option( self::$prefix . 'easy_digital_downloads' ) && function_exists( 'EDD' ) ) {

			$edd_product_options = self::get_all_post_options( 'download' );

			$options[] = array(
				'key'     => 'x_edd_product_purchased',
				'label'   => esc_html__( 'User purchased download', 'bricksextras' ) . ' (EDD)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $edd_product_options,
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_edd_product_purchased_id',
				'label'   => esc_html__( 'User purchased download ID', 'bricksextras' ) . ' (EDD)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					// translators: %s is the type of value to provide (e.g., ID).
					'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
				),
			);

			/* Recurring payment in EDD Pro. */
			if ( class_exists( '\EDD_Recurring_Subscriber' ) ) {

				$options[] = array(
					'key'     => 'x_edd_subscribed',
					'label'   => esc_html__( 'User subscription', 'bricksextras' ) . ' (EDD)',
					'group'   => 'x_member_conditions',
					'compare' => array(
						'type'        => 'select',
						'options'     => array(
							'==' => esc_html__( 'Active', 'bricks' ),
							'!=' => esc_html__( 'Inactive', 'bricks' ),
						),
						'placeholder' => esc_html__( 'Active', 'bricks' ),
					),
					'value'   => array(
						'type'        => 'select',
						'options'     => $edd_product_options,
						'placeholder' => esc_html__( 'Select option', 'bricks' ),
					),
				);

				$options[] = array(
					'key'     => 'x_edd_subscribed_id',
					'label'   => esc_html__( 'User subscription ID', 'bricksextras' ) . ' (EDD)',
					'group'   => 'x_member_conditions',
					'compare' => array(
						'type'        => 'select',
						'options'     => array(
							'==' => esc_html__( 'Active', 'bricks' ),
							'!=' => esc_html__( 'Inactive', 'bricks' ),
						),
						'placeholder' => esc_html__( 'Active', 'bricks' ),
					),
					'value'   => array(
						'type'        => 'text',
						// translators: %s is the type of value to provide (e.g., ID).
						'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
					),
				);

			}
		}

		/* WP Members. */

		if ( class_exists( '\WP_Members_Products' ) && get_option( self::$prefix . 'wp_members' ) ) {

			$options[] = array(
				'key'     => 'x_wp_members_membership',
				'label'   => esc_html__( 'User membership', 'bricksextras' ) . ' (WP Members)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'Active', 'bricks' ),
						'!=' => esc_html__( 'Inactive', 'bricks' ),
					),
					'placeholder' => esc_html__( 'Active', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'wpmem_product' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_wp_members_membership_id',
				'label'   => esc_html__( 'User membership ID', 'bricksextras' ) . ' (WP Members)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'Active', 'bricks' ),
						'!=' => esc_html__( 'Inactive', 'bricks' ),
					),
					'placeholder' => esc_html__( 'Active', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Product ID', 'bricks' ),
				),
			);

		}

		/* restrict content */

		if ( get_option( self::$prefix . 'restrict_content' ) && function_exists( 'rcp_get_membership_levels' ) ) {

			$level_options = array();

			$levels = rcp_get_membership_levels( 'active' );

			if ( ! empty( $levels ) ) {
				foreach ( $levels as $level ) {
					$level_options[ $level->id ] = $level->name;
				}
			}

			$options[] = array(
				'key'     => 'x_rcp_membership_level',
				'label'   => esc_html__( 'Membership level', 'bricksextras' ) . ' (Restrict Content)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'=='        => esc_html__( 'User belongs to', 'bricksextras' ),
						'active'    => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Active', 'bricks' ) . ')',
						'cancelled' => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Cancelled', 'bricksextras' ) . ')',
						'pending'   => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Pending', 'bricksextras' ) . ')',
						'expired'   => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Expired', 'bricksextras' ) . ')',
						'!='        => esc_html__( 'User does not belong to', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'User belongs to', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $level_options,
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_rcp_membership_level_id',
				'label'   => esc_html__( 'Membership level ID', 'bricksextras' ) . ' (Restrict Content)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'=='        => esc_html__( 'User belongs to', 'bricksextras' ),
						'active'    => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Active', 'bricks' ) . ')',
						'cancelled' => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Cancelled', 'bricksextras' ) . ')',
						'pending'   => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Pending', 'bricksextras' ) . ')',
						'expired'   => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Expired', 'bricksextras' ) . ')',
						'!='        => esc_html__( 'User does not belong to', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'User belongs to', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'text',
					// translators: %s is the type of value to provide (e.g., ID).
					'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
				),
			);

			$options[] = array(
				'key'     => 'x_rcp_has_active_membership',
				'label'   => esc_html__( 'User has active membership', 'bricksextras' ) . ' (Restrict Content)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_rcp_has_paid_membership',
				'label'   => esc_html__( 'User has paid membership', 'bricksextras' ) . ' (Restrict Content)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		/* WishList Member. */
		if ( get_option( self::$prefix . 'wishlist_member' ) && function_exists( 'wlmapi_get_levels' ) ) {
			$wlm_levels = wlmapi_get_levels();

			// Initialize an empty array to store the result.
			$wlm_result_array = array();

			// Check if the 'levels' key exists in the $wlm_levels array, and it contains the 'level' sub-array.
			if ( isset( $wlm_levels['levels'] ) && isset( $wlm_levels['levels']['level'] ) ) {
					// Loop through the 'level' sub-array and extract the id and name values.
				foreach ( $wlm_levels['levels']['level'] as $level ) {
					if ( isset( $level['id'] ) && isset( $level['name'] ) ) {
							// Add the id and name as key-value pairs to the $wlm_result_array.
							$wlm_result_array[ $level['id'] ] = $level['name'];
					}
				}
			}

			$options[] = array(
				'key'     => 'x_wishlist_member',
				'label'   => esc_html__( 'Member Level', 'bricksextras' ) . ' (WishList Member)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'=='        => esc_html__( 'User belongs to', 'bricksextras' ),
						'!='        => esc_html__( 'User does not belong to', 'bricksextras' ),
						'active'    => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Active', 'bricks' ) . ')',
						'cancelled' => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Cancelled', 'bricksextras' ) . ')',
					),
					'placeholder' => esc_html__( 'User belongs to', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $wlm_result_array,
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_wishlist_member_id',
				'label'   => esc_html__( 'Member Level ID', 'bricksextras' ) . ' (WishList Member)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'=='        => esc_html__( 'User belongs to', 'bricksextras' ),
						'!='        => esc_html__( 'User does not belong to', 'bricksextras' ),
						'active'    => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Active', 'bricks' ) . ')',
						'cancelled' => esc_html__( 'User belongs to ', 'bricksextras' ) . ' (' . esc_html__( 'Cancelled', 'bricksextras' ) . ')',
					),
					'placeholder' => esc_html__( 'User belongs to', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'text',
					// translators: %s is the type of value to provide (e.g., ID).
					'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
				),
			);

		}

		/* Sure Members */
		if ( get_option( self::$prefix . 'sure_members' ) && method_exists( '\SureMembers\Inc\Access_Groups', 'check_if_user_has_access' ) ) {

			$options[] = array(
				'key'     => 'x_sure_members_access_groups',
				'label'   => esc_html__( 'Member access group', 'bricksextras' ) . ' (SureMembers)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'wsm_access_group' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_sure_members_access_groups_id',
				'label'   => esc_html__( 'Member access group ID', 'bricksextras' ) . ' (SureMembers)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					// translators: %s is the type of value to provide (e.g., ID).
					'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
				),
			);

		}

		/* Paid Memberships Pro */
		if ( get_option( self::$prefix . 'pmp_membership_level' ) && class_exists( '\PMPro_Membership_Level' ) ) {

			global $pmpro_levels;

			$bricks_pmpro_levels = array( 'non-members' => esc_html__( 'Non-Members', 'bricksextras' ) );

			if ( ! empty( $pmpro_levels ) ) {
				foreach ( $pmpro_levels as $pmpro_level ) {
					$bricks_pmpro_levels[ $pmpro_level->id ] = $pmpro_level->name;
				}
			}

			$options[] = array(
				'key'     => 'x_pmp_membership_level',
				'label'   => esc_html__( 'Level', 'bricksextras' ) . ' (Paid Memberships Pro)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $bricks_pmpro_levels,
					'placeholder' => esc_html__( 'Non-Members', 'bricksextras' ),
				),
			);

			$options[] = array(
				'key'     => 'x_pmp_membership_level_id',
				'label'   => esc_html__( 'Level ID', 'bricksextras' ) . ' (Paid Memberships Pro)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					// translators: %s is the type of value to provide (e.g., ID).
					'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
				),
			);

		}

		/* Woocommerce Subscriptions */
		if ( get_option( self::$prefix . 'woocommerce_subscriptions' ) && class_exists( '\WC_Subscriptions' ) ) {

			$options[] = array(
				'key'     => 'x_woocommerce_subscriptions',
				'label'   => esc_html__( 'Has active subscription', 'bricksextras' ) . ' (Woocommerce Subscriptions)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'product' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_woocommerce_subscriptions_id',
				'label'   => esc_html__( 'Has active subscription ID', 'bricksextras' ) . ' (Woocommerce Subscriptions)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					// translators: %s is the type of value to provide (e.g., ID).
					'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
				),
			);

		}

		/* Woocommerce Memberships */
		if ( get_option( self::$prefix . 'woocommerce_memberships' ) && class_exists( '\WC_Memberships' ) ) {

			$options[] = array(
				'key'     => 'x_woocommerce_memberships',
				'label'   => esc_html__( 'Has active membership', 'bricksextras' ) . ' (Woocommerce Memberships)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'wc_membership_plan' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_woocommerce_memberships_id',
				'label'   => esc_html__( 'Has active membership ID', 'bricksextras' ) . ' (Woocommerce Memberships)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					// translators: %s is the type of value to provide (e.g., ID).
					'placeholder' => sprintf( esc_html__( 'Provide %s', 'bricksextras' ), 'ID' ),
				),
			);

		}

		/* general conditions */

		if ( get_option( self::$prefix . 'at_least_1_search_result' ) ) {

			$options[] = array(
				'key'     => 'x_at_least_1_search_result',
				'label'   => esc_html__( 'At least one search result', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'present'     => esc_html__( 'Present', 'bricksextras' ),
						'not_present' => esc_html__( 'Not present', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'Present', 'bricksextras' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'archive_type' ) ) {

			$options[] = array(
				'key'     => 'x_archive_type',
				'label'   => esc_html__( 'Archive type', 'bricks' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'posts_page' => esc_html__( 'Posts page (blog)', 'bricksextras' ),
						'category'   => esc_html__( 'Category', 'bricks' ),
						'tag'        => esc_html__( 'Tag', 'bricks' ),
						'taxonomy'   => esc_html__( 'Taxonomy', 'bricks' ),
						'search'     => esc_html__( 'Search', 'bricks' ),
						'author'     => esc_html__( 'Author', 'bricks' ),
						'date'       => esc_html__( 'Date', 'bricks' ),
						'wc'         => esc_html__( 'Product Category/Product Tag', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'Category', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'authored_by_logged_in_user' ) ) {

			// Authored by Logged-In User.
			$options[] = array(
				'key'     => 'x_authored_by_logged_in_user',
				'label'   => esc_html__( 'Authored by logged-in user', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'post_ancestor' ) ) {

			// Post Ancestor.
			$options[] = array(
				'key'     => 'x_post_ancestor',
				'label'   => esc_html__( 'Post ancestor', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type' => 'text',
				),
			);

		}

		if ( get_option( self::$prefix . 'post_type' ) ) {

			// Post Ancestor.
			$options[] = array(
				'key'     => 'x_post_type',
				'label'   => esc_html__( 'Post type', 'bricks' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '!=', 'bricks' ),
				),
				'value'   => array(
					'type' => 'text',
				),
			);

		}

		if ( get_option( self::$prefix . 'post_comment_count' ) ) {

			// Post Comment Count.
			$options[] = array(
				'key'     => 'x_post_comment_count',
				'label'   => esc_html__( 'Post comment count', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'post_category' ) ) {

			$post_categories_array = array();

			if ( bricks_is_builder() ) {

				// Post Category.
				$post_categories = get_categories( array( 'hide_empty' => false ) );

				foreach ( $post_categories as $post_category ) {
					$post_categories_array[ $post_category->term_id ] = $post_category->name;
				}
			}

			$options[] = array(
				'key'     => 'x_post_category',
				'label'   => esc_html__( 'Post category', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $post_categories_array,
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'post_tag' ) ) {

			$post_tags_array = array();

			if ( bricks_is_builder() ) {

				// Post Tag.
				$post_tags = get_tags( array( 'hide_empty' => false ) );

				foreach ( $post_tags as $post_tag ) {
					$post_tags_array[ $post_tag->term_id ] = $post_tag->name;
				}
			}

			$options[] = array(
				'key'     => 'x_post_tag',
				'label'   => esc_html__( 'Post tag', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $post_tags_array,
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'is_child' ) ) {

			// Is Child.
			$options[] = array(
				'key'     => 'x_is_child',
				'label'   => esc_html__( 'Is child', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'is_parent' ) ) {

			// Is Parent.
			$options[] = array(
				'key'     => 'x_is_parent',
				'label'   => esc_html__( 'Is parent', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'in_favorites_loop' ) ) {

			// Is Parent.
			$options[] = array(
				'key'     => 'x_in_favorites_loop',
				'label'   => esc_html__( 'In favorites loop', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'language_visitor' ) ) {

			// Language (visitor).
			$options[] = array(
				'key'     => 'x_language_visitor',
				'label'   => esc_html__( 'Language', 'bricks' ) . ' (' . esc_html__( 'Visitor', 'bricksextras' ) . ')',
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => 'en-US',
				),
			);

		}

		if ( get_option( self::$prefix . 'category_archive' ) ) {

			$post_categories_array2 = array();

			if ( bricks_is_builder() ) {

				// Category Archive.
				$post_categories2 = get_categories( array( 'hide_empty' => false ) );

				foreach ( $post_categories2 as $post_category2 ) {
					$post_categories_array2[ $post_category2->term_id ] = $post_category2->name;
				}
			}

			$options[] = array(
				'key'     => 'x_category_archive',
				'label'   => esc_html__( 'Category archive', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $post_categories_array2,
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'tag_archive' ) ) {

			$post_tags_array2 = array();

			if ( bricks_is_builder() ) {

				// Tag Archive.
				$post_tags2 = get_tags( array( 'hide_empty' => false ) );

				foreach ( $post_tags2 as $post_tag2 ) {
					$post_tags_array2[ $post_tag2->term_id ] = $post_tag2->name;
				}
			}

			$options[] = array(
				'key'     => 'x_tag_archive',
				'label'   => esc_html__( 'Tag archive', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $post_tags_array2,
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'post_publish_date' ) ) {

			// Post publish date.
			$options[] = array(
				'key'     => 'x_post_publish_date',
				'label'   => esc_html__( 'Post publish date', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'past'  => esc_html__( 'in the past', 'bricksextras' ),
						'today' => esc_html__( 'today', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'in the past', 'bricksextras' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'page_type' ) ) {
			// Normal ones.
			$options_normal = array(
				'front_page' => esc_html__( 'Front page', 'bricks' ),
				'blog'       => esc_html__( 'Posts page (blog)', 'bricksextras' ),
				'page'       => esc_html__( 'Static Page', 'bricksextras' ),
				'post'       => esc_html__( 'Single post', 'bricksextras' ),
				'singular'   => esc_html__( 'Singular', 'bricksextras' ),
				'single'     => esc_html__( 'Single', 'bricks' ),
				'archive'    => esc_html__( 'Archive', 'bricks' ),
				'category'   => esc_html__( 'Category archive', 'bricksextras' ),
				'tag'        => esc_html__( 'Tag archive', 'bricksextras' ),
				'search'     => esc_html__( 'Search results', 'bricks' ),
				'author'     => esc_html__( 'Author archive', 'bricksextras' ),
				'tax'        => esc_html__( 'Taxonomy archive', 'bricksextras' ),
				'error'      => esc_html__( '404', 'bricks' ),
				'date'       => esc_html__( 'Date archive', 'bricksextras' ),
			);

			// WooCommerce specific.
			$options_wc = array(
				'wc'                    => 'WooCommerce',
				'wc_shop'               => 'WC ' . esc_html__( 'Shop', 'bricksextras' ),
				'wc_product_category'   => 'WC ' . esc_html__( 'Product category', 'bricks' ),
				'wc_product_tag'        => 'WC ' . esc_html__( 'Product tag', 'bricks' ),
				'wc_product'            => 'WC ' . esc_html__( 'Single product', 'bricks' ),
				'wc_cart'               => 'WC ' . esc_html__( 'Cart', 'bricks' ),
				'wc_checkout'           => 'WC ' . esc_html__( 'Checkout', 'bricks' ),
				'wc_account'            => 'WC ' . esc_html__( 'Account', 'bricks' ),
				'wc_endpoint'           => 'WC ' . esc_html__( 'Endpoint', 'bricks' ),
				'wc_order_pay'          => 'WC ' . esc_html__( 'Order pay', 'bricksextras' ),
				'wc_order_received'     => 'WC ' . esc_html__( 'Order received', 'bricksextras' ),
				'wc_view_order'         => 'WC ' . esc_html__( 'View order', 'bricks' ),
				'wc_edit_account'       => 'WC ' . esc_html__( 'Edit account', 'bricks' ),
				'wc_edit_address'       => 'WC ' . esc_html__( 'Edit address', 'bricks' ),
				'wc_lost_password'      => 'WC ' . esc_html__( 'Lost password', 'bricks' ),
				'wc_customer_logout'    => 'WC ' . esc_html__( 'Customer logout', 'bricksextras' ),
				'wc_add_payment_method' => 'WC ' . esc_html__( 'Add payment method', 'bricks' ),
			);

			$options_arr = class_exists( '\WooCommerce' ) ? array_merge( $options_normal, $options_wc ) : $options_normal;

			// Page type.
			$options[] = array(
				'key'     => 'x_page_type',
				'label'   => esc_html__( 'Page type', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $options_arr,
					'placeholder' => esc_html__( 'Page', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'wpml_language' ) && defined( 'ICL_SITEPRESS_VERSION' ) ) {

			$languages = apply_filters( 'wpml_active_languages', null, 'orderby=name&order=asc' );

			$languages_array = array();

			foreach ( $languages as $language ) {
					$languages_array[ $language['language_code'] ] = $language['translated_name'];
			}

			$options[] = array(
				'key'     => 'x_wpml_language',
				'label'   => esc_html__( 'Language', 'bricks' ) . ' (WPML)',
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $languages_array,
					'placeholder' => $languages_array[ apply_filters( 'wpml_default_language', null ) ],
				),
			);

		}

		if ( get_option( self::$prefix . 'page_parent' ) ) {

			// array of all Pages of the current Page as ID => Page title.
			$parent_pages = self::get_all_post_options( 'page' );

			// Filter the above array to remove posts that do not have children.
			$parent_pages = array_filter(
				$parent_pages,
				function ( $title, $id ) {
					return count( get_pages( array( 'child_of' => $id ) ) ) !== 0;
				},
				ARRAY_FILTER_USE_BOTH
			);

			$options[] = array(
				'key'     => 'x_page_parent',
				'label'   => esc_html__( 'Page parent', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $parent_pages,
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		// Polylang.
		if ( get_option( self::$prefix . 'polylang_language' ) && function_exists( 'pll_count_posts' ) ) {

			$polylang_arr = array_combine( pll_languages_list(), pll_languages_list( array( 'fields' => 'name' ) ) );

			$options[] = array(
				'key'     => 'x_polylang_language',
				'label'   => esc_html__( 'Language', 'bricks' ) . ' (Polylang)',
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $polylang_arr,
					'placeholder' => pll_default_language( 'name' ),
				),
			);

		}

		// TranslatePress.
		if ( get_option( self::$prefix . 'translatepress_language' ) && class_exists( '\TRP_Translate_Press' ) ) {

			$trp = TRP_Translate_Press::get_trp_instance();

			$trp_settings = $trp->get_component( 'settings' );

			$language_codes_array = $trp_settings->get_settings()['publish-languages'];

			$language_codes_array = array_combine( $language_codes_array, $language_codes_array );

			$options[] = array(
				'key'     => 'x_translatepress_language',
				'label'   => esc_html__( 'Language', 'bricks' ) . ' (TranslatePress)',
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $language_codes_array,
					'placeholder' => array_values( $language_codes_array )[0],
				),
			);

		}

		// Published During Last.
		if ( get_option( self::$prefix . 'published_during_last' ) ) {

			$options[] = array(
				'key'     => 'x_published_during_last',
				'label'   => esc_html__( 'Published during the last', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'day'   => esc_html__( '1 day', 'bricks' ),
						'week'  => esc_html__( '1 week', 'bricks' ),
						'month' => esc_html__( '1 month', 'bricksextras' ),
						'year'  => esc_html__( '1 year', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		// Loop item number.
		if ( get_option( self::$prefix . 'loop_item_number' ) ) {

			$options[] = array(
				'key'     => 'x_loop_item_number',
				'label'   => esc_html__( 'Loop item number', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array_merge(
						self::get_maths_compare_options(),
						array(
							'every'  => esc_html__( 'every', 'bricksextras' ),
							'modulo' => esc_html__( 'sequence pattern', 'bricksextras' ) . ' (n:m)',
						)
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '1', 'bricks' ),
				),
			);

		}

		// Current Month.
		if ( get_option( self::$prefix . 'current_month' ) ) {

			$options[] = array(
				'key'     => 'x_current_month',
				'label'   => esc_html__( 'Current month', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'January'   => esc_html__( 'January', 'bricks' ),
						'February'  => esc_html__( 'February', 'bricks' ),
						'March'     => esc_html__( 'March', 'bricks' ),
						'April'     => esc_html__( 'April', 'bricks' ),
						'May'       => esc_html__( 'May', 'bricks' ),
						'June'      => esc_html__( 'June', 'bricks' ),
						'July'      => esc_html__( 'July', 'bricks' ),
						'August'    => esc_html__( 'August', 'bricks' ),
						'September' => esc_html__( 'September', 'bricks' ),
						'October'   => esc_html__( 'October', 'bricks' ),
						'November'  => esc_html__( 'November', 'bricks' ),
						'December'  => esc_html__( 'December', 'bricks' ),
					),
					'placeholder' => esc_html( wp_date( 'F' ) ),
				),
			);

		}

		// Current Day.
		if ( get_option( self::$prefix . 'current_day' ) ) {

			$options[] = array(
				'key'     => 'x_current_day',
				'label'   => esc_html__( 'Current day of month', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'1'  => esc_html__( '1', 'bricks' ),
						'2'  => esc_html__( '2', 'bricks' ),
						'3'  => esc_html__( '3', 'bricks' ),
						'4'  => esc_html__( '4', 'bricks' ),
						'5'  => esc_html__( '5', 'bricks' ),
						'6'  => esc_html__( '6', 'bricks' ),
						'7'  => esc_html__( '7', 'bricks' ),
						'8'  => esc_html__( '8', 'bricks' ),
						'9'  => esc_html__( '9', 'bricks' ),
						'10' => esc_html__( '10', 'bricks' ),
						'11' => esc_html__( '11', 'bricks' ),
						'12' => esc_html__( '12', 'bricks' ),
						'13' => esc_html__( '13', 'bricks' ),
						'14' => esc_html__( '14', 'bricks' ),
						'15' => esc_html__( '15', 'bricks' ),
						'16' => esc_html__( '16', 'bricks' ),
						'17' => esc_html__( '17', 'bricks' ),
						'18' => esc_html__( '18', 'bricks' ),
						'19' => esc_html__( '19', 'bricks' ),
						'20' => esc_html__( '20', 'bricks' ),
						'21' => esc_html__( '21', 'bricks' ),
						'22' => esc_html__( '22', 'bricks' ),
						'23' => esc_html__( '23', 'bricks' ),
						'24' => esc_html__( '24', 'bricks' ),
						'25' => esc_html__( '25', 'bricks' ),
						'26' => esc_html__( '26', 'bricks' ),
						'27' => esc_html__( '27', 'bricks' ),
						'28' => esc_html__( '28', 'bricks' ),
						'29' => esc_html__( '29', 'bricks' ),
						'30' => esc_html__( '30', 'bricks' ),
						'31' => esc_html__( '31', 'bricks' ),
					),
					'placeholder' => esc_html( wp_date( 'j' ) ),
				),
			);

		}

		// Current Year.
		if ( get_option( self::$prefix . 'current_year' ) ) {

			$options[] = array(
				'key'     => 'x_current_year',
				'label'   => esc_html__( 'Current year', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html( wp_date( 'Y' ) ),
				),
			);

		}

		// Current Taxonomy Term Has Child.
		if ( get_option( self::$prefix . 'current_taxonomy_term_has_child' ) ) {

			$options[] = array(
				'key'     => 'x_current_taxonomy_term_has_child',
				'label'   => esc_html__( 'Current Taxonomy Term Has Child', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// Current Taxonomy Term Has Parent.
		if ( get_option( self::$prefix . 'current_taxonomy_term_has_parent' ) ) {

			$options[] = array(
				'key'     => 'x_current_taxonomy_term_has_parent',
				'label'   => esc_html__( 'Current Taxonomy Term Has Parent', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'current_taxonomy_term_is_descendant_of' ) ) {

			$taxonomy_terms_array = array();

			if ( bricks_is_builder() ) {

				$taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );

				foreach ( $taxonomies as $taxonomy ) {
					$terms = get_terms(
						array(
							'taxonomy'   => $taxonomy->name,
							'hide_empty' => false,
						)
					);

					if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
						foreach ( $terms as $term ) {
							$taxonomy_terms_array[ $term->term_id ] = $taxonomy->label . ': ' . $term->name;
						}
					}
				}
			}

			$options[] = array(
				'key'     => 'x_current_taxonomy_term_is_descendant_of',
				'label'   => esc_html__( 'Current Taxonomy Term Is Descendant Of', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $taxonomy_terms_array,
					'placeholder' => esc_html__( 'Select term', 'bricksextras' ),
				),
			);

			$options[] = array(
				'key'     => 'x_current_taxonomy_term_is_descendant_of_id',
				'label'   => esc_html__( 'Current Taxonomy Term Is Descendant Of', 'bricksextras' ) . ' (ID)',
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Enter term ID', 'bricksextras' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'current_taxonomy_term_is' ) ) {

			$taxonomy_terms_array = array();

			if ( bricks_is_builder() ) {

				$taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );

				foreach ( $taxonomies as $taxonomy ) {
					$terms = get_terms(
						array(
							'taxonomy'   => $taxonomy->name,
							'hide_empty' => false,
						)
					);

					if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
						foreach ( $terms as $term ) {
							$taxonomy_terms_array[ $term->term_id ] = $taxonomy->label . ': ' . $term->name;
						}
					}
				}
			}

			$options[] = array(
				'key'     => 'x_current_taxonomy_term_is',
				'label'   => esc_html__( 'Current Taxonomy Term Is', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $taxonomy_terms_array,
					'placeholder' => esc_html__( 'Select term', 'bricksextras' ),
				),
			);

			$options[] = array(
				'key'     => 'x_current_taxonomy_term_is_id',
				'label'   => esc_html__( 'Current Taxonomy Term Is', 'bricksextras' ) . ' (ID)',
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Enter term ID', 'bricksextras' ),
				),
			);

		}

		// Body classes.
		if ( get_option( self::$prefix . 'body_classes' ) ) {

			$options[] = array(
				'key'     => 'x_body_classes',
				'label'   => esc_html__( 'Body classes', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'Include', 'bricks' ),
						'!=' => esc_html__( 'Exclude', 'bricks' ),
					),
					'placeholder' => esc_html__( 'Include', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Enter a single class name', 'bricksextras' ),
				),
			);

		}

		// Has custom excerpt.
		if ( get_option( self::$prefix . 'has_custom_excerpt' ) ) {

			$options[] = array(
				'key'     => 'x_has_custom_excerpt',
				'label'   => esc_html__( 'Has custom excerpt', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// Has post content.
		if ( get_option( self::$prefix . 'has_post_content' ) ) {

			$options[] = array(
				'key'     => 'x_has_post_content',
				'label'   => esc_html__( 'Has post content', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// Has child category.
		if ( get_option( self::$prefix . 'has_child_category' ) ) {

			$options[] = array(
				'key'     => 'x_has_child_category',
				'label'   => esc_html__( 'Has child category', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'False', 'bricks' ),
				),
			);

		}

		// Date field value.
		if ( get_option( self::$prefix . 'date_field_value' ) ) {

			$options[] = array(
				'key'     => 'x_date_field_value',
				'label'   => esc_html__( 'Date field value', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'past'   => esc_html__( 'is in the past', 'bricksextras' ),
						'today'  => esc_html__( 'is today', 'bricksextras' ),
						'future' => esc_html__( 'is in the future', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'is in the future', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Select custom field', 'bricksextras' ),
				),
			);

		}

		// Datetime field value.
		if ( get_option( self::$prefix . 'datetime_field_value' ) ) {

			$options[] = array(
				'key'     => 'x_datetime_field_value',
				'label'   => esc_html__( 'Datetime field value', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'past'   => esc_html__( 'is in the past', 'bricksextras' ),
						'future' => esc_html__( 'is in the future', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'is in the future', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Select custom field', 'bricksextras' ),
				),
			);

		}

		// Author has CPT entry.
		if ( get_option( self::$prefix . 'author_has_cpt_entry' ) ) {

			$options[] = array(
				'key'     => 'x_author_has_cpt_entry',
				'label'   => esc_html__( 'Author has CPT entry', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => Helpers::get_public_post_types(),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		// CPT has at least 1 published entry.
		if ( get_option( self::$prefix . 'cpt_has_at_least_1_entry' ) ) {

			$options[] = array(
				'key'     => 'x_cpt_has_at_least_1_entry',
				'label'   => esc_html__( 'At least 1 entry exists', 'bricksextras' ),
				'group'   => 'x_extras_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'for this post type', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'for this post type', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => Helpers::get_public_post_types(),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		/* WooCommerce conditions. */

		if ( get_option( self::$prefix . 'cart_empty' ) && class_exists( '\WooCommerce' ) ) {

			// Cart empty.
			$options[] = array(
				'key'     => 'x_cart_empty',
				'label'   => esc_html__( 'Cart empty', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'empty'     => esc_html__( 'Empty', 'bricks' ),
						'not_empty' => esc_html__( 'Not empty', 'bricks' ),
					),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		// Product in Cart.
		if ( get_option( self::$prefix . 'product_in_cart' ) && class_exists( '\WooCommerce' ) ) {
			$options[] = array(
				'key'     => 'x_product_in_cart',
				'label'   => esc_html__( 'Product in cart', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'product' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_product_in_cart_id',
				'label'   => esc_html__( 'Product in cart', 'bricksextras' ) . ' (ID)',
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Product ID', 'bricks' ),
				),
			);
		}

		// user purchased product.
		if ( get_option( self::$prefix . 'user_purchased_product' ) && class_exists( '\WooCommerce' ) ) {
			$options[] = array(
				'key'     => 'x_user_purchased_product',
				'label'   => esc_html__( 'User purchased product', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'has purchased', 'bricksextras' ),
						'!=' => esc_html__( 'has not purchased', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'has purchased', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'product' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_user_purchased_product_id',
				'label'   => esc_html__( 'User purchased product', 'bricksextras' ) . ' (ID)',
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'has purchased', 'bricksextras' ),
						'!=' => esc_html__( 'has not purchased', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'has purchased', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Product ID', 'bricks' ),
				),
			);
		}

		// user just purchased product.
		if ( get_option( self::$prefix . 'user_just_purchased_product' ) && class_exists( '\WooCommerce' ) ) {
			$options[] = array(
				'key'     => 'x_user_just_purchased_product',
				'label'   => esc_html__( 'User just purchased product', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'product' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_user_just_purchased_product_id',
				'label'   => esc_html__( 'User just purchased product', 'bricksextras' ) . ' (ID)',
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Product ID', 'bricks' ),
				),
			);
		}

		// cart total.
		if ( get_option( self::$prefix . 'cart_total' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_cart_total',
				// translators: %s is the currency code (e.g., USD).
				'label'   => sprintf( esc_html__( 'Cart total (%s)', 'bricksextras' ), get_option( 'woocommerce_currency' ) ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		// cart total minus shipping.
		if ( get_option( self::$prefix . 'cart_total_minus_shipping' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_cart_total_minus_shipping',
				// translators: %s is the currency code (e.g., USD).
				'label'   => sprintf( esc_html__( 'Cart total (%s) excl. shipping', 'bricksextras' ), get_option( 'woocommerce_currency' ) ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		// cart weight.
		if ( get_option( self::$prefix . 'cart_weight' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_cart_weight',
				// translators: %s is the weight unit (e.g., kg, lbs).
				'label'   => sprintf( esc_html__( 'Cart weight (%s)', 'bricksextras' ), get_option( 'woocommerce_weight_unit' ) ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		// product is virtual.
		if ( get_option( self::$prefix . 'product_is_virtual' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_is_virtual',
				'label'   => esc_html__( 'Product is virtual', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// product is downloadable.
		if ( get_option( self::$prefix . 'product_is_downloadable' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_is_downloadable',
				'label'   => esc_html__( 'Product is downloadable', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// purchased current product.
		if ( get_option( self::$prefix . 'user_purchased_current_product' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_user_purchased_current_product',
				'label'   => esc_html__( 'User purchased current product', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// has pending order.
		if ( get_option( self::$prefix . 'user_has_pending_order' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_user_has_pending_order',
				'label'   => esc_html__( 'User has pending order', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// has order with status.
		if ( get_option( self::$prefix . 'user_has_order_with_status' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_user_has_order_with_status',
				'label'   => esc_html__( 'User has order with status', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'wc-pending'        => esc_html__( 'Pending payment', 'bricksextras' ),
						'wc-processing'     => esc_html__( 'Processing', 'bricksextras' ),
						'wc-on-hold'        => esc_html__( 'On hold', 'bricksextras' ),
						'wc-completed'      => esc_html__( 'Completed', 'bricksextras' ),
						'wc-cancelled'      => esc_html__( 'Cancelled', 'bricksextras' ),
						'wc-refunded'       => esc_html__( 'Refunded', 'bricksextras' ),
						'wc-failed'         => esc_html__( 'Failed', 'bricksextras' ),
						'wc-checkout-draft' => esc_html__( 'Draft', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'Select status', 'bricksextras' ),
				),
			);

		}

		// product in stock.
		if ( get_option( self::$prefix . 'product_in_stock' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_in_stock',
				'label'   => esc_html__( 'Product in stock', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// product weight.
		if ( get_option( self::$prefix . 'product_weight' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_weight',
				// translators: %s is the weight unit (e.g., kg, lbs).
				'label'   => sprintf( esc_html__( 'Product weight (%s)', 'bricksextras' ), get_option( 'woocommerce_weight_unit' ) ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		// product rating.
		if ( get_option( self::$prefix . 'product_rating' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_rating',
				'label'   => esc_html__( 'Product rating', 'bricks' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'cart_count' ) && class_exists( '\WooCommerce' ) ) {

			// Cart count.
			$options[] = array(
				'key'     => 'x_cart_count',
				'label'   => esc_html__( 'Cart count', 'bricks' ) . ' (' . esc_html__( 'Items', 'bricks' ) . ')',
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		if ( get_option( self::$prefix . 'product_type' ) && class_exists( '\WooCommerce' ) ) {

			// product type.
			$options[] = array(
				'key'     => 'x_product_type',
				'label'   => esc_html__( 'Product type', 'bricks' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'is', 'bricks' ),
						'!=' => esc_html__( 'is not', 'bricks' ),
					),
					'placeholder' => esc_html__( 'is', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'simple'   => esc_html__( 'Simple', 'bricks' ),
						'grouped'  => esc_html__( 'Grouped', 'bricks' ),
						'variable' => esc_html__( 'Variable', 'bricks' ),
						'external' => esc_html__( 'External', 'bricks' ) . ' / ' . esc_html__( 'Affiliate', 'bricks' ),
					),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		// product on backorder.
		if ( get_option( self::$prefix . 'product_on_backorder' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_on_backorder',
				'label'   => esc_html__( 'Product on backorder', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// product upsells.
		if ( get_option( self::$prefix . 'product_upsell_count' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_upsell_count',
				'label'   => esc_html__( 'Product upsell count', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '>', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		// product upsells.
		if ( get_option( self::$prefix . 'product_crosssells_count' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_crosssells_count',
				'label'   => esc_html__( 'Product cross-sells count', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => self::get_maths_compare_options(),
					'placeholder' => esc_html__( '>', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( '0', 'bricks' ),
				),
			);

		}

		// product backorders allowed.
		if ( get_option( self::$prefix . 'product_backorders_allowed' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_backorders_allowed',
				'label'   => esc_html__( 'Product allows backorders', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);

		}

		// product has category.
		if ( get_option( self::$prefix . 'product_has_category' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_has_category',
				'label'   => esc_html__( 'Product has category', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_product_terms( 'product_cat' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		// product has tag.
		if ( get_option( self::$prefix . 'product_has_tag' ) && class_exists( '\WooCommerce' ) ) {

			$options[] = array(
				'key'     => 'x_product_has_tag',
				'label'   => esc_html__( 'Product has tag', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_product_terms( 'product_tag' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

		}

		// Current Product in Cart.
		if ( get_option( self::$prefix . 'current_product_in_cart' ) && class_exists( '\WooCommerce' ) ) {
			$options[] = array(
				'key'     => 'x_current_product_in_cart',
				'label'   => esc_html__( 'Current product in cart', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => array(
						'true'  => esc_html__( 'True', 'bricks' ),
						'false' => esc_html__( 'False', 'bricks' ),
					),
					'placeholder' => esc_html__( 'True', 'bricks' ),
				),
			);
		}

		// Selected product in cart has a coupon applied.
		if ( get_option( self::$prefix . 'product_in_cart_has_coupon' ) && class_exists( '\WooCommerce' ) ) {
			$options[] = array(
				'key'     => 'x_product_in_cart_has_coupon',
				'label'   => esc_html__( 'Product in cart has a coupon applied', 'bricksextras' ),
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'product' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_product_in_cart_has_coupon_id',
				'label'   => esc_html__( 'Product in cart has a coupon applied', 'bricksextras' ) . ' (ID)',
				'group'   => 'x_wc_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Product ID', 'bricks' ),
				),
			);
		}

		/* FluentCart conditions. */

		if ( get_option( self::$prefix . 'fluentcart' ) && class_exists( '\FluentCart\App\Helpers\Status' ) ) {

			// Helper method to get subscription statuses from FluentCart.
			$subscription_statuses = array();
			if ( class_exists( '\FluentCart\App\Helpers\Status' ) ) {
				$subscription_statuses = \FluentCart\App\Helpers\Status::getSubscriptionStatuses();
			}

			// user purchased product (FluentCart).
			$options[] = array(
				'key'     => 'x_fluentcart_user_purchased_product',
				'label'   => esc_html__( 'User purchased product', 'bricksextras' ) . ' (FluentCart)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'has purchased', 'bricksextras' ),
						'!=' => esc_html__( 'has not purchased', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'has purchased', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'fluent-products' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_fluentcart_user_purchased_product_id',
				'label'   => esc_html__( 'User purchased product ID', 'bricksextras' ) . ' (FluentCart)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( 'has purchased', 'bricksextras' ),
						'!=' => esc_html__( 'has not purchased', 'bricksextras' ),
					),
					'placeholder' => esc_html__( 'has purchased', 'bricksextras' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Product ID', 'bricks' ),
				),
			);

			// user's subscription (FluentCart).
			$subscription_compare_options       = $subscription_statuses;
			$subscription_compare_options['!='] = esc_html__( 'Does not have subscription', 'bricksextras' );

			$options[] = array(
				'key'     => 'x_fluentcart_user_subscription',
				'label'   => esc_html__( 'User\'s subscription to product', 'bricksextras' ) . ' (FluentCart)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => $subscription_compare_options,
					'placeholder' => esc_html__( 'Active', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'fluent-products' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_fluentcart_user_subscription_id',
				'label'   => esc_html__( 'User\'s subscription to product ID', 'bricksextras' ) . ' (FluentCart)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => $subscription_compare_options,
					'placeholder' => esc_html__( 'Active', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Product ID', 'bricks' ),
				),
			);

			// user has any subscription with status (FluentCart).
			$subscription_value_options        = $subscription_statuses;
			$subscription_value_options['any'] = esc_html__( 'Any status', 'bricksextras' );

			$options[] = array(
				'key'     => 'x_fluentcart_user_has_any_subscription',
				'label'   => esc_html__( 'User has subscription', 'bricksextras' ) . ' (FluentCart)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => $subscription_value_options,
					'placeholder' => esc_html__( 'Active', 'bricks' ),
				),
			);

			// user just purchased FluentCart product.
			$options[] = array(
				'key'     => 'x_user_just_purchased_fluentcart_product',
				'label'   => esc_html__( 'User just purchased FluentCart product', 'bricksextras' ),
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'select',
					'options'     => self::get_all_post_options( 'fluent-products' ),
					'placeholder' => esc_html__( 'Select option', 'bricks' ),
				),
			);

			$options[] = array(
				'key'     => 'x_user_just_purchased_fluentcart_product_id',
				'label'   => esc_html__( 'User just purchased FluentCart product', 'bricksextras' ) . ' (ID)',
				'group'   => 'x_member_conditions',
				'compare' => array(
					'type'        => 'select',
					'options'     => array(
						'==' => esc_html__( '==', 'bricks' ),
						'!=' => esc_html__( '!=', 'bricks' ),
					),
					'placeholder' => esc_html__( '==', 'bricks' ),
				),
				'value'   => array(
					'type'        => 'text',
					'placeholder' => esc_html__( 'Product ID', 'bricks' ),
				),
			);

		}

		return $options;
	}

	/**
	 * Get all post options for a specific post type.
	 *
	 * @param string $post_type Post type to retrieve options for.
	 * @return array Array of post options.
	 */
	private static function get_all_post_options( $post_type = 'post' ): array {

		if ( ! bricks_is_builder() ) {
			return array();
		}

			$args = array(
				'post_type'      => $post_type,
				'posts_per_page' => -1,
				'orderby'        => 'title',
				'order'          => 'ASC',
			);

			$posts = get_posts( $args );

			$posts_options = array();

			if ( ! empty( $posts ) ) {
				foreach ( $posts as $post ) {
					$posts_options[ $post->ID ] = $post->post_title;
				}
			}

			wp_reset_postdata();

			return $posts_options;
	}

	/**
	 * Get mathematics comparison options.
	 *
	 * @return array Array of comparison operators.
	 */
	private static function get_maths_compare_options(): array {

		return array(
			'==' => esc_html__( '==', 'bricks' ),
			'!=' => esc_html__( '!=', 'bricks' ),
			'>=' => esc_html__( '>=', 'bricks' ),
			'<=' => esc_html__( '<=', 'bricks' ),
			'>'  => esc_html__( '>', 'bricks' ),
			'<'  => esc_html__( '<', 'bricks' ),
		);
	}


	/**
	 * Perform mathematical comparison between amount and value.
	 *
	 * @param float  $amount  Amount to compare.
	 * @param mixed  $value   Value to compare against.
	 * @param string $compare Comparison operator.
	 * @param bool   $use_float Whether to use float comparison.
	 * @return bool Result of comparison.
	 */
	private static function get_maths_compare( float $amount, $value, string $compare, bool $use_float = true ): bool {

		switch ( $compare ) {
			case '==':
				return $use_float ? floatval( $value ) === floatval( $amount ) : intval( $value ) === intval( $amount );

			case '>':
				return $use_float ? $amount > floatval( $value ) : $amount > intval( $value );

			case '>=':
				return $use_float ? $amount >= floatval( $value ) : $amount >= intval( $value );

			case '<':
				return $use_float ? $amount < floatval( $value ) : $amount < intval( $value );

			case '<=':
				return $use_float ? $amount <= floatval( $value ) : $amount <= intval( $value );

			case '!=':
				return $use_float ? floatval( $value ) !== floatval( $amount ) : intval( $value ) !== intval( $amount );

			default:
				return false;
		}
	}

	/**
	 * Get product terms for a specific taxonomy.
	 *
	 * @param string $taxonomy Taxonomy name.
	 * @return array Array of product terms.
	 */
	public static function get_product_terms( $taxonomy ): array {

		if ( ! bricks_is_builder() ) {
			return array();
		}

		$product_terms = get_terms(
			array(
				'taxonomy'   => $taxonomy,
				'hide_empty' => true,
			)
		);

		$product_terms_array = array();

		foreach ( $product_terms as $product_term ) {
			$product_terms_array[ $product_term->term_id ] = $product_term->name;
		}

		return $product_terms_array;
	}

	/**
	 * Execute condition checks based on condition key.
	 *
	 * @param bool   $result The current result.
	 * @param string $condition_key The condition key to check.
	 * @param array  $condition The condition configuration.
	 * @return bool Whether the condition is met.
	 */
	public static function run_conditions( bool $result, string $condition_key, array $condition ): bool {

		$condition_met = false;

		switch ( $condition_key ) {

			case 'x_at_least_1_search_result':
				$condition_met = self::execute_x_at_least_1_search_result( $condition );
				break;

			case 'x_archive_type':
				$condition_met = self::execute_x_archive_type( $condition );
				break;

			case 'x_authored_by_logged_in_user':
				$condition_met = self::execute_x_authored_by_logged_in_user( $condition );
				break;

			case 'x_is_archive':
				$condition_met = self::execute_x_is_archive( $condition );
				break;

			case 'x_post_ancestor':
				$condition_met = self::execute_x_post_ancestor( $condition );
				break;

			case 'x_post_type':
				$condition_met = self::execute_x_post_type( $condition );
				break;

			case 'x_post_comment_count':
				$condition_met = self::execute_x_post_comment_count( $condition );
				break;

			case 'x_post_category':
				$condition_met = self::execute_x_post_category( $condition );
				break;

			case 'x_post_tag':
				$condition_met = self::execute_x_post_tag( $condition );
				break;

			case 'x_is_homepage':
				$condition_met = self::execute_x_is_homepage( $condition );
				break;

			case 'x_is_child':
				$condition_met = self::execute_x_is_child( $condition );
				break;

			case 'x_is_parent':
				$condition_met = self::execute_x_is_parent( $condition );
				break;
			case 'x_in_favorites_loop':
				$condition_met = self::execute_x_in_favorites_loop( $condition );
				break;
			case 'x_password_protect':
				$condition_met = self::execute_x_password_protect( $condition );
				break;

			case 'x_language_visitor':
				$condition_met = self::execute_x_language_visitor( $condition );
				break;

			case 'x_category_archive':
				$condition_met = self::execute_x_category_archive( $condition );
				break;

			case 'x_tag_archive':
				$condition_met = self::execute_x_tag_archive( $condition );
				break;

			case 'x_post_publish_date':
				$condition_met = self::execute_x_post_publish_date( $condition );
				break;

			case 'x_page_type':
				$condition_met = self::execute_x_page_type( $condition );
				break;

			case 'x_wpml_language':
				$condition_met = self::execute_x_wpml_language( $condition );
				break;

			case 'x_page_parent':
				$condition_met = self::execute_x_page_parent( $condition );
				break;

			case 'x_polylang_language':
				$condition_met = self::execute_x_polylang_language( $condition );
				break;

			case 'x_translatepress_language':
				$condition_met = self::execute_x_translatepress_language( $condition );
				break;

			case 'x_published_during_last':
				$condition_met = self::execute_x_published_during_last( $condition );
				break;

			case 'x_loop_item_number':
				$condition_met = self::execute_x_loop_item_number( $condition );
				break;

			case 'x_current_month':
				$condition_met = self::execute_x_current_month( $condition );
				break;

			case 'x_current_day':
				$condition_met = self::execute_x_current_day( $condition );
				break;

			case 'x_current_year':
				$condition_met = self::execute_x_current_year( $condition );
				break;

			case 'x_current_taxonomy_term_has_child':
				$condition_met = self::execute_x_current_taxonomy_term_has_child( $condition );
				break;

			case 'x_current_taxonomy_term_has_parent':
				$condition_met = self::execute_x_current_taxonomy_term_has_parent( $condition );
				break;

			case 'x_current_taxonomy_term_is_descendant_of':
			case 'x_current_taxonomy_term_is_descendant_of_id':
				$condition_met = self::execute_x_current_taxonomy_term_is_descendant_of( $condition );
				break;

			case 'x_current_taxonomy_term_is':
			case 'x_current_taxonomy_term_is_id':
				$condition_met = self::execute_x_current_taxonomy_term_is( $condition );
				break;

			case 'x_body_classes':
				$condition_met = self::execute_x_body_classes( $condition );
				break;

			case 'x_has_custom_excerpt':
				$condition_met = self::execute_x_has_custom_excerpt( $condition );
				break;

			case 'x_has_post_content':
				$condition_met = self::execute_x_has_post_content( $condition );
				break;

			case 'x_has_child_category':
				$condition_met = self::execute_x_has_child_category( $condition );
				break;

			case 'x_date_field_value':
				$condition_met = self::execute_x_date_field_value( $condition );
				break;

			case 'x_datetime_field_value':
				$condition_met = self::execute_x_datetime_field_value( $condition );
				break;

			case 'x_author_has_cpt_entry':
				$condition_met = self::execute_x_author_has_cpt_entry( $condition );
				break;

			case 'x_cpt_has_at_least_1_entry':
				$condition_met = self::execute_x_cpt_has_at_least_1_entry( $condition );
				break;

			/* member conditions */

			case 'x_memberpress_membership':
			case 'x_memberpress_membership_id':
				$condition_met = self::execute_x_memberpress_membership( $condition );
				break;
			case 'x_edd_product_purchased':
				$condition_met = self::execute_x_edd_product_purchased( $condition );
				break;
			case 'x_edd_product_purchased_id':
				$condition_met = self::execute_x_edd_product_purchased_id( $condition );
				break;

			case 'x_edd_subscribed':
				$condition_met = self::execute_x_edd_subscribed( $condition );
				break;
			case 'x_edd_subscribed_id':
				$condition_met = self::execute_x_edd_subscribed_id( $condition );
				break;

			case 'x_wp_members_membership':
			case 'x_wp_members_membership_id':
				$condition_met = self::execute_x_wp_members_membership( $condition );
				break;

			case 'x_rcp_membership_level':
			case 'x_rcp_membership_level_id':
				$condition_met = self::execute_x_rcp_membership_level( $condition );
				break;

			case 'x_rcp_has_active_membership':
				$condition_met = self::execute_x_rcp_has_active_membership( $condition );
				break;

			case 'x_rcp_has_paid_membership':
				$condition_met = self::execute_x_rcp_has_paid_membership( $condition );
				break;

			case 'x_wishlist_member':
			case 'x_wishlist_member_id':
				$condition_met = self::execute_x_wishlist_member( $condition );
				break;

			case 'x_sure_members_access_groups':
			case 'x_sure_members_access_groups_id':
				$condition_met = self::execute_x_sure_members_access_groups( $condition );
				break;

			case 'x_pmp_membership_level':
			case 'x_pmp_membership_level_id':
					$condition_met = self::execute_x_pmp_membership_level( $condition );
				break;

			case 'x_woocommerce_subscriptions':
			case 'x_woocommerce_subscriptions_id':
				$condition_met = self::execute_x_woocommerce_subscriptions( $condition );
				break;

			case 'x_woocommerce_memberships':
			case 'x_woocommerce_memberships_id':
				$condition_met = self::execute_x_woocommerce_memberships( $condition );
				break;

			/* WooCommerce conditions */

			case 'x_cart_empty':
				$condition_met = self::execute_x_cart_empty( $condition );
				break;

			case 'x_cart_total':
				$condition_met = self::execute_x_cart_total( $condition );
				break;

			case 'x_cart_total_minus_shipping':
				$condition_met = self::execute_x_cart_total_minus_shipping( $condition );
				break;

			case 'x_cart_weight':
				$condition_met = self::execute_x_cart_weight( $condition );
				break;

			case 'x_product_in_cart':
				$condition_met = self::execute_x_product_in_cart( $condition );
				break;
			case 'x_product_in_cart_id':
				$condition_met = self::execute_x_product_in_cart_id( $condition );
				break;

			case 'x_user_purchased_product':
				$condition_met = self::execute_x_user_purchased_product( $condition );
				break;
			case 'x_user_purchased_product_id':
				$condition_met = self::execute_x_user_purchased_product_id( $condition );
				break;

			case 'x_user_just_purchased_product':
			case 'x_user_just_purchased_product_id':
				$condition_met = self::execute_x_user_just_purchased_product( $condition );
				break;

			case 'x_user_just_purchased_fluentcart_product':
			case 'x_user_just_purchased_fluentcart_product_id':
				$condition_met = self::execute_x_user_just_purchased_fluentcart_product( $condition );
				break;

			case 'x_product_is_virtual':
				$condition_met = self::execute_x_product_is_virtual( $condition );
				break;

			case 'x_product_is_downloadable':
				$condition_met = self::execute_x_product_is_downloadable( $condition );
				break;

			case 'x_user_purchased_current_product':
				$condition_met = self::execute_x_user_purchased_current_product( $condition );
				break;

			case 'x_user_has_pending_order':
				$condition_met = self::execute_x_user_has_pending_order( $condition );
				break;

			case 'x_user_has_order_with_status':
				$condition_met = self::execute_x_user_has_order_with_status( $condition );
				break;

			case 'x_product_in_stock':
				$condition_met = self::execute_x_product_in_stock( $condition );
				break;

			case 'x_product_weight':
				$condition_met = self::execute_x_product_weight( $condition );
				break;

			case 'x_product_rating':
				$condition_met = self::execute_x_product_rating( $condition );
				break;

			case 'x_cart_count':
				$condition_met = self::execute_x_cart_count( $condition );
				break;

			case 'x_product_type':
				$condition_met = self::execute_x_product_type( $condition );
				break;

			case 'x_product_on_backorder':
				$condition_met = self::execute_x_product_on_backorder( $condition );
				break;

			case 'x_product_upsell_count':
				$condition_met = self::execute_x_product_upsell_count( $condition );
				break;

			case 'x_product_crosssells_count':
				$condition_met = self::execute_x_product_crosssells_count( $condition );
				break;

			case 'x_product_backorders_allowed':
				$condition_met = self::execute_x_product_backorders_allowed( $condition );
				break;

			case 'x_product_has_category':
				$condition_met = self::execute_x_product_has_category( $condition );
				break;

			case 'x_product_has_tag':
				$condition_met = self::execute_x_product_has_tag( $condition );
				break;

			case 'x_current_product_in_cart':
				$condition_met = self::execute_x_current_product_in_cart( $condition );
				break;

			case 'x_product_in_cart_has_coupon':
				$condition_met = self::execute_x_product_in_cart_has_coupon( $condition );
				break;

			case 'x_product_in_cart_has_coupon_id':
				$condition_met = self::execute_x_product_in_cart_has_coupon_id( $condition );
				break;

			/* FluentCart conditions */

			case 'x_fluentcart_user_purchased_product':
				$condition_met = self::execute_x_fluentcart_user_purchased_product( $condition );
				break;
			case 'x_fluentcart_user_purchased_product_id':
				$condition_met = self::execute_x_fluentcart_user_purchased_product_id( $condition );
				break;

			case 'x_fluentcart_user_subscription':
				$condition_met = self::execute_x_fluentcart_user_subscription( $condition );
				break;
			case 'x_fluentcart_user_subscription_id':
				$condition_met = self::execute_x_fluentcart_user_subscription_id( $condition );
				break;

			case 'x_fluentcart_user_has_any_subscription':
				$condition_met = self::execute_x_fluentcart_user_has_any_subscription( $condition );
				break;

			default:
				$condition_met = $result;
				break;
		}

		return $condition_met;
	}


	/* functions for each condition */

	/**
	 * Execute condition to check if there is at least 1 search result.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_at_least_1_search_result( $condition ): bool {

		// If user value is empty, we set it to 'present' as default.
		$user_value = $condition['value'] ?? 'present';

		// Get the number of search results.
		global $wp_query;
		$search_results_count = $wp_query->found_posts;

		return 'present' === $user_value ? $search_results_count > 0 : 0 === $search_results_count;
	}

	/**
	 * Execute condition to check archive type.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_archive_type( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to 'category' as default.
		$compare    = $condition['compare'] ?? '==';
		$user_value = $condition['value'] ?? 'category';

		// Return true or false depending on the chosen value.
		if ( '==' === $compare ) {
			switch ( $user_value ) {
				case 'posts_page':
					return is_home();

				case 'category':
					return is_category();

				case 'tag':
					return is_tag();

				case 'taxonomy':
					return is_tax();

				case 'search':
					return is_search();

				case 'author':
					return is_author();

				case 'date':
					return is_date();

				case 'wc':
					return class_exists( '\WooCommerce' ) && is_product_taxonomy();

				default:
					return is_category();
			}
		} else {
			switch ( $user_value ) {
				case 'posts_page':
					return ! is_home();

				case 'category':
					return ! is_category();

				case 'tag':
					return ! is_tag();

				case 'taxonomy':
					return ! is_tax();

				case 'search':
					return ! is_search();

				case 'author':
					return ! is_author();

				case 'date':
					return ! is_date();

				case 'wc':
					return ! ( class_exists( '\WooCommerce' ) && is_product_taxonomy() );

				default:
					return ! is_category();
			}
		}
	}

	/**
	 * Execute condition to check if author has CPT entry.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_author_has_cpt_entry( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare    = $condition['compare'] ?? '==';
		$user_value = $condition['value'] ?? '';

		if ( '' === $user_value ) {
				return true;
		}

		$posts_count = intval( count_user_posts( get_current_user_id(), $user_value ) );

		// Return true or false depending on the chosen value.
		return '==' === $compare ? $posts_count > 0 : 0 === $posts_count;
	}

	/**
	 * Execute condition to check if CPT has at least 1 entry.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_cpt_has_at_least_1_entry( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare    = $condition['compare'] ?? '==';
		$user_value = $condition['value'] ?? '';

		if ( '' === $user_value ) {
				return true;
		}

		return wp_count_posts( $user_value )->publish > 0;
	}

	/**
	 * Execute condition to check if post is authored by logged in user.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_authored_by_logged_in_user( $condition ): bool {

		// If user value is empty, we set it to 'true' as default.
		$value = $condition['value'] ?? 'true';

		global $post;

		if ( ! $post ) {
			return false;
		}

		switch ( $value ) {
			case 'false':
				if ( is_user_logged_in() ) {
						return get_the_author_meta( 'ID', $post->post_author ) !== wp_get_current_user()->ID;
				} else {
						return false;
				}
				break;

			case 'true':
			default:
				if ( is_user_logged_in() ) {
					return get_the_author_meta( 'ID', $post->post_author ) === wp_get_current_user()->ID;
				} else {
					return false;
				}
		}
	}

	/**
	 * Execute condition to check post comment count.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_post_comment_count( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to 0 as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 0;

		// Get comments count for the current post.

		global $post;

		if ( ! $post ) {
			return false;
		}

		$comments_count = get_comments_number( $post->ID );

		$value = bricks_render_dynamic_data( $value );

		return self::get_maths_compare( $comments_count, intval( $value ), $compare, false );
	}

	/**
	 * Execute condition to check if current page is an archive.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_is_archive( $condition ): bool {

		// If user value is empty, we set it to '' as default.
		$value = $condition['value'] ?? 'false';

		return 'true' === $value ? is_archive() : ! is_archive();
	}

	/**
	 * Execute condition to check post ancestor.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_post_ancestor( $condition ): bool {

		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? false;

		if ( ! $value ) {
			return false;
		}

		$post_ancestors = get_post_ancestors( get_the_ID() );

		$value = bricks_render_dynamic_data( $value );

		$value_array = explode( ',', $value );

		$has_ancestor = false;

		foreach ( $value_array as $value ) {

			if ( in_array( intval( $value ), $post_ancestors, true ) ) {
				$has_ancestor = true;
			}
		}

		return '==' === $compare ? $has_ancestor : ! $has_ancestor;
	}

	/**
	 * Execute condition to check post type.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_post_type( $condition ): bool {

		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? false;

		if ( ! $value ) {
			return false;
		}

		$is_post_type = get_post_type() === $value;

		return '==' === $compare ? $is_post_type : ! $is_post_type;
	}

	/**
	 * Execute condition to check post category.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_post_category( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		// Array of current post category IDs.
		global $post;

		if ( ! $post ) {
			return false;
		}
		$post_categories       = get_the_category( $post->ID );
		$post_categories_array = array();
		foreach ( $post_categories as $post_category ) {
			$post_categories_array[] = $post_category->term_id;
		}

		// Return true or false depending on the chosen value.
		return '==' === $compare ? in_array( intval( $value ), $post_categories_array, true ) : ! in_array( intval( $value ), $post_categories_array, true );
	}

	/**
	 * Execute condition to check post tag.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_post_tag( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		// Array of current post tag IDs.
		global $post;

		if ( ! $post ) {
			return false;
		}
		$post_tags       = get_the_tags( $post->ID );
		$post_tags_array = array();

		if ( ! is_array( $post_tags ) ) {
			return false;
		}

		foreach ( $post_tags as $post_tag ) {
			$post_tags_array[] = $post_tag->term_id;
		}

		// Return true or false depending on the chosen value.
		return '==' === $compare ? in_array( intval( $value ), $post_tags_array, true ) : ! in_array( intval( $value ), $post_tags_array, true );
	}

	/**
	 * Execute condition to check if current page is homepage.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_is_homepage( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$value = $condition['value'] ?? 'false';

		return 'true' === $value ? is_front_page() : ! is_front_page();
	}

	/**
	 * Execute condition to check if current page is a child page.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_is_child( $condition ): bool {

		// If user value is empty, we set it to 'false' as default.
		$value = $condition['value'] ?? 'false';

		global $post;

		if ( ! $post ) {
			return false;
		}

		return 'true' === $value ? $post->post_parent > 0 : 0 === $post->post_parent;
	}

	/**
	 * Execute condition to check if current page is a parent page.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_is_parent( $condition ): bool {

		// If user value is empty, we set it to 'true' as default.
		$value = $condition['value'] ?? 'true';

		global $post;

		if ( ! $post ) {
			return false;
		}

		$children = get_pages(
			array(
				'child_of'  => $post->ID,
				'post_type' => $post->post_type,
			)
		);

		if ( ! is_array( $children ) ) {
			return 'false' === $value;
		}

		return 'true' === $value ? count( $children ) > 0 : 0 === count( $children );
	}

	/**
	 * Execute condition to check if in favorites loop.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_in_favorites_loop( $condition ): bool {

		// If user value is empty, we set it to 'true' as default.
		$value = $condition['value'] ?? 'true';

		global $post;

		if ( ! $post ) {
			return false;
		}

		$condition_met = ( isset( $post->in_favorites_loop ) && true === $post->in_favorites_loop );

		return 'true' === $value ? $condition_met : ! $condition_met;
	}

	/**
	 * Execute condition to check if post is password protected.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_password_protect( $condition ): bool {

		// If user value is empty, we set it to 'false' as default.
		$value = $condition['value'] ?? 'false';

		// Return true or false depending on the chosen value.
		global $post;

		if ( ! $post ) {
			return false;
		}

		return 'true' === $value ? post_password_required( $post ) : ! post_password_required( $post );
	}

	/**
	 * Execute condition to check visitor language.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_language_visitor( $condition ): bool {

		// If compare is empty, we set it to '=' as default
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 'en-US';

		// Return true or false depending on the chosen value.
		// Get the languages set in the browser.
		$languages = Helpers::get_server_value( 'HTTP_ACCEPT_LANGUAGE' );
		$languages = $languages ? $languages : false;

		if ( false === $languages ) {
			return true;
		}

		// Get the position of "," in languages.
		$pos = strpos( $languages, ',' );

		// Get the first language before the first occurrence of comma.
		$language = substr( $languages, 0, $pos );

		return '==' === $compare ? $language === $value : $language !== $value;
	}

	/**
	 * Execute condition to check category archive.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_category_archive( $condition ): bool {

		// If compare is empty, we set it to '=' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '1';

		// Return true or false depending on the chosen value.
		return '==' === $compare ? is_category( $value ) : ! is_category( $value );
	}

	/**
	 * Execute condition to check tag archive.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_tag_archive( $condition ): bool {

		// If compare is empty, we set it to '=' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		if ( '' === $value ) {
			return true;
		}

		// Return true or false depending on the chosen value.
		return '==' === $compare ? is_tag( $value ) : ! is_tag( $value );
	}

	/**
	 * Execute condition to check post publish date.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_post_publish_date( $condition ): bool {

		// If user value is empty, we set it to 'past' as default.
		$value = $condition['value'] ?? 'past';

		$publish_date = get_post_datetime( get_the_ID() )->format( 'Y-m-d' );
		$current_date = wp_date( 'Y-m-d' );

		return 'past' === $value ? strtotime( $publish_date ) < strtotime( $current_date ) : strtotime( $publish_date ) === strtotime( $current_date );
	}

	/**
	 * Execute condition to check page type.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_page_type( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 'page';

		switch ( $value ) {

			case 'post':
				return '==' === $compare ? is_singular( 'post' ) : ! is_singular( 'post' );

			case 'front_page':
				return '==' === $compare ? is_front_page() : ! is_front_page();

			case 'blog':
				return '==' === $compare ? is_home() : ! is_home();

			case 'error':
				return '==' === $compare ? is_404() : ! is_404();

			case 'search':
				return '==' === $compare ? is_search() : ! is_search();

			case 'singular':
				return '==' === $compare ? is_singular() : ! is_singular();

			case 'single':
				return '==' === $compare ? is_single() : ! is_single();

			case 'archive':
				return '==' === $compare ? is_archive() : ! is_archive();

			case 'category':
				return '==' === $compare ? is_category() : ! is_category();

			case 'tag':
				return '==' === $compare ? is_tag() : ! is_tag();

			case 'author':
				return '==' === $compare ? is_author() : ! is_author();

			case 'date':
				return '==' === $compare ? is_date() : ! is_date();

			case 'tax':
				return '==' === $compare ? is_tax() : ! is_tax();

			case 'wc':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_woocommerce() : ! is_woocommerce();
				} else {
					return false;
				}

			case 'wc_shop':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_shop() : ! is_shop();
				} else {
					return false;
				}
				break;

			case 'wc_product':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_product() : ! is_product();
				} else {
					return false;
				}
				break;

			case 'wc_product_category':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_product_category() : ! is_product_category();
				} else {
					return false;
				}
				break;

			case 'wc_product_tag':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_product_tag() : ! is_product_tag();
				} else {
					return false;
				}
				break;

			case 'wc_cart':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_cart() : ! is_cart();
				} else {
					return false;
				}
				break;

			case 'wc_checkout':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_checkout() : ! is_checkout();
				} else {
					return false;
				}
				break;

			case 'wc_account':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_account_page() : ! is_account_page();
				} else {
					return false;
				}
				break;

			case 'wc_endpoint':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url() : ! is_wc_endpoint_url();
				} else {
					return false;
				}
				break;

			case 'wc_order_pay':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url( 'order-pay' ) : ! is_wc_endpoint_url( 'order-pay' );
				} else {
					return false;
				}
				break;

			case 'wc_order_received':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url( 'order-received' ) : ! is_wc_endpoint_url( 'order-received' );
				} else {
					return false;
				}
				break;

			case 'wc_view_order':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url( 'view-order' ) : ! is_wc_endpoint_url( 'view-order' );
				} else {
					return false;
				}
				break;

			case 'wc_edit_account':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url( 'edit-account' ) : ! is_wc_endpoint_url( 'edit-account' );
				} else {
					return false;
				}
				break;

			case 'wc_edit_address':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url( 'edit-address' ) : ! is_wc_endpoint_url( 'edit-address' );
				} else {
					return false;
				}
				break;

			case 'wc_lost_password':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url( 'lost-password' ) : ! is_wc_endpoint_url( 'lost-password' );
				} else {
					return false;
				}
				break;

			case 'wc_customer_logout':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url( 'customer-logout' ) : ! is_wc_endpoint_url( 'customer-logout' );
				} else {
					return false;
				}
				break;

			case 'wc_add_payment_method':
				if ( class_exists( '\WooCommerce' ) ) {
					return '==' === $compare ? is_wc_endpoint_url( 'add-payment-method' ) : ! is_wc_endpoint_url( 'add-payment-method' );
				} else {
					return false;
				}
				break;

			case 'page':
			default:
				return '==' === $compare ? is_page() : ! is_page();

		}
	}

	/**
	 * Execute condition to check WPML language.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_wpml_language( $condition ): bool {

		if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) {
			return true;
		}

		$current_language = apply_filters( 'wpml_current_language', null );

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? apply_filters( 'wpml_default_language', null );

		// Return true or false depending on the chosen value.
		return '==' === $compare ? $value === $current_language : $value !== $current_language;
	}

	/**
	 * Execute condition to check page parent.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_page_parent( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		if ( ! $value ) {
			return true;
		}

		// Check if current Page is a child of $value.
		global $post;

		if ( ! $post ) {
			return false;
		}

		return '==' === $compare ? intval( $value ) === $post->post_parent : intval( $value ) !== $post->post_parent;
	}

	/**
	 * Execute condition to check Polylang language.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_polylang_language( $condition ): bool {

		if ( ! function_exists( 'pll_count_posts' ) ) {
			return true;
		}

		$current_language = pll_current_language();

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? pll_default_language();

		// Return true or false depending on the chosen value.
		return '==' === $compare ? $current_language === $value : $current_language !== $value;
	}

	/**
	 * Execute condition to check TranslatePress language.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_translatepress_language( $condition ): bool {

		if ( ! class_exists( '\TRP_Translate_Press' ) ) {
			return true;
		}

		$trp = TRP_Translate_Press::get_trp_instance();

		$trp_settings = $trp->get_component( 'settings' );

		$language_codes_array = $trp_settings->get_settings()['publish-languages'];

		$current_language = get_locale();

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to the default language as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? $language_codes_array[0];

		// Return true or false depending on the chosen value.
		return '==' === $compare ? $value === $current_language : $value !== $current_language;
	}

	/**
	 * Execute condition to check if published during last period.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_published_during_last( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		if ( ! $value ) {
			return true;
		}

		$args = array(
			'date_query'     => array(
				array(
					'after' => '1 ' . $value . ' ago',
				),
			),
			'post_type'      => 'any',
			'posts_per_page' => -1,
		);

		$date_query = new WP_Query( $args );

		$present = in_array( get_the_ID(), wp_list_pluck( $date_query->posts, 'ID' ), true );

		return '==' === $compare ? $present : ! $present;
	}

	/**
	 * Execute condition to check loop item number.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_loop_item_number( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to 1 as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 1;

		$value = bricks_render_dynamic_data( $value );

		if ( method_exists( '\Bricks\Query', 'get_query_object' ) ) {
			$query_object = Query::get_query_object();

			if ( $query_object ) {
				$loop_item_number = intval( $query_object::get_loop_index() ) + 1;
			}
		} else {
			$loop_item_number = 0;
		}

		$loop_item_number = $loop_item_number ?? 1;

		if ( 'every' === $compare ) {
			return $loop_item_number % intval( $value ) === 0;
		} elseif ( 'modulo' === $compare ) {

			if ( strpos( $value, ':' ) !== false ) {

				$parts = explode( ':', $value );

				if ( count( $parts ) === 2 ) {
					$divisor   = intval( $parts[0] );
					$remainder = intval( $parts[1] );

					if ( 0 === $divisor ) {
						return false;
					}

					return ( $loop_item_number % $divisor ) === $remainder;
				}
			}

			$traditional_pattern = '/\s*%\s*(\d+)\s*=\s*(\d+)\s*/';
			if ( preg_match( $traditional_pattern, $value, $matches ) ) {
				$divisor   = intval( $matches[1] );
				$remainder = intval( $matches[2] );

				if ( 0 === $divisor ) {
					return false;
				}

				return ( $loop_item_number % $divisor ) === $remainder;
			}

			return false;
		} else {
			return self::get_maths_compare( $loop_item_number, intval( $value ), $compare, false );
		}
	}

	/**
	 * Execute condition to check current month.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_current_month( $condition ): bool {

		$current_month = wp_date( 'F' );

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to the current month name as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? $current_month;

		return '==' === $compare ? $value === $current_month : $value !== $current_month;
	}

	/**
	 * Execute condition to check current day.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_current_day( $condition ): bool {

		$current_day = wp_date( 'j' );

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to current day of the week as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? $current_day;

		return '==' === $compare ? $value === $current_day : $value !== $current_day;
	}

	/**
	 * Execute condition to check current year.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_current_year( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to the current year as default.
		$compare = $condition['compare'] ?? '==';

		$current_year = wp_date( 'Y' );

		$value = $condition['value'] ?? $current_year;

		return '==' === $compare ? $value === $current_year : $value !== $current_year;
	}

	/**
	 * Execute condition to check if current taxonomy term has child.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_current_taxonomy_term_has_child( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to the current year as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 'true';

		// Get the current term.
		$current_term = get_queried_object();

		$has_child = false;

		// Check if it's a term object and has children.
		if ( is_a( $current_term, 'WP_Term' ) && $current_term->term_id ) {

			$child_terms = get_term_children( $current_term->term_id, $current_term->taxonomy );

			if ( is_array( $child_terms ) ) {
				$has_child = ! empty( $child_terms );
			}
		}

		return 'true' === $value ? $has_child : ! $has_child;
	}

	/**
	 * Execute condition to check if current taxonomy term has parent.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_current_taxonomy_term_has_parent( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to the current year as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 'true';

		// Get the current term.
		$current_term = get_queried_object();

		$has_parent = false;

		// Check if it's a term object and has parent.
		if ( is_a( $current_term, 'WP_Term' ) && $current_term->term_id ) {

			$parent_terms = get_ancestors( $current_term->term_id, $current_term->taxonomy );

			if ( is_array( $parent_terms ) ) {
				$has_parent = ! empty( $parent_terms );
			}
		}

		return 'true' === $value ? $has_parent : ! $has_parent;
	}

	/**
	 * Execute condition to check if current term is descendant of specified term.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_current_taxonomy_term_is_descendant_of( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = bricks_render_dynamic_data( $condition['value'] ) ?? '';

		if ( ! $value ) {
			return true;
		}

		// Get the current term being viewed.
		$current_term = get_queried_object();

		// Check if we're on a taxonomy archive page.
		if ( ! is_a( $current_term, 'WP_Term' ) || ! $current_term->term_id ) {
			return '==' === $compare ? false : true;
		}

		// Get all ancestors of the current term.
		$ancestor_ids = get_ancestors( $current_term->term_id, $current_term->taxonomy, 'taxonomy' );

		// Check if the specified term is in the ancestors array.
		$is_descendant = in_array( intval( $value ), $ancestor_ids, true );

		return '==' === $compare ? $is_descendant : ! $is_descendant;
	}

	/**
	 * Execute condition to check if current taxonomy term matches specified term.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_current_taxonomy_term_is( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = bricks_render_dynamic_data( $condition['value'] ) ?? '';

		if ( ! $value ) {
			return true;
		}

		// Get the current term being viewed.
		$current_term = get_queried_object();

		// Check if we're on a taxonomy archive page.
		if ( ! is_a( $current_term, 'WP_Term' ) || ! $current_term->term_id ) {
			return '==' === $compare ? false : true;
		}

		// Check if the current term matches the specified term.
		$is_match = intval( $value ) === $current_term->term_id;

		return '==' === $compare ? $is_match : ! $is_match;
	}

	/**
	 * Execute condition to check body class.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_body_classes( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		if ( ! $value ) {
			return true;
		}

		$body_classes = get_body_class();

		return '==' === $compare ? in_array( $value, $body_classes, true ) : ! in_array( $value, $body_classes, true );
	}

	/**
	 * Execute condition to check if post has custom excerpt.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_has_custom_excerpt( $condition ): bool {

		// If user value is empty, we set it to 'true' as default.
		$value = $condition['value'] ?? 'true';

		$has_excerpt = has_excerpt( get_the_ID() );

		return 'true' === $value ? $has_excerpt : ! $has_excerpt;
	}

	/**
	 * Execute condition to check if post has content.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_has_post_content( $condition ): bool {

		// If user value is empty, we set it to 'true' as default.
		$value = $condition['value'] ?? 'true';

		global $post;

		if ( ! $post ) {
			return false;
		}

		$content_length = strlen( $post->post_content );

		return 'true' === $value ? $content_length : ! $content_length;
	}

	/**
	 * Execute condition to check if category has child.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_has_child_category( $condition ): bool {

		// If user value is empty, we set it to 'false' as default.
		$value = $condition['value'] ?? 'false';

		if ( 'false' === $value && ! is_category() ) {
			return true;
		}

		$cat = get_queried_object();

		$has_child_category = false;

		if ( 0 === $cat->category_parent ) { // If the current category is a top-level category.
			$children = get_categories(
				array(
					'child_of'   => $cat->term_id,
					'hide_empty' => false,
				)
			);

			$has_child_category = count( $children ) > 0;
		}

		return 'true' === $value ? $has_child_category : ! $has_child_category;
	}

	/**
	 * Execute condition to check date field value.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_date_field_value( $condition ): bool {

		// If compare is empty, we set it to 'future' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? 'future';
		$value   = $condition['value'] ?? '';

		if ( ! $value ) {
			return true;
		}

		$value = str_replace( '}', ':Y-m-d}', $value );

		$value = bricks_render_dynamic_data( $value );

		try {
			$value = new DateTimeImmutable( $value, wp_timezone() );
			$value = $value->format( 'Y-m-d' );
		} catch ( \Exception $e ) {
			return true;
		}

		$today = current_datetime(); // Retrieves the current time as an object using the site's timezone.
		$today = $today->format( 'Y-m-d' );

		switch ( $compare ) {

			case 'today':
				return $value === $today;

			case 'past':
				return $value < $today;

			case 'future':
			default:
				return $value > $today;
		}
	}

	/**
	 * Execute condition to check datetime field value.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_datetime_field_value( $condition ): bool {

		// If compare is empty, we set it to 'future' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? 'future';
		$value   = $condition['value'] ?? '';

		if ( ! $value ) {
			return true;
		}

		$value = str_replace( '}', ':Y-m-d H:i:s}', $value );

		$value = bricks_render_dynamic_data( $value );

		try {
			$value = new DateTimeImmutable( $value, wp_timezone() );
			$value = $value->format( 'U' );
		} catch ( \Exception $e ) {
			return true;
		}

		$now = time(); // Retrieves the current Unix timestamp.

		switch ( $compare ) {
			case 'future':
				return $value > $now;

			case 'past':
				return $value < $now;

			default:
				return $value > $now;
		}
	}




	/* membership conditions */

	/**
	 * Execute condition to check MemberPress membership.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_memberpress_membership( $condition ): bool {

		$compare    = $condition['compare'] ?? '==';
		$user_value = isset( $condition['value'] ) ? bricks_render_dynamic_data( $condition['value'] ) : false;

		/* abort if no value */
		if ( ! $user_value || ! class_exists( '\MeprSubscription' ) ) {
			return true;
		}

		$current_user_membership = current_user_can( 'mepr-active', "membership: $user_value" );

		return '==' === $compare ? $current_user_membership : ! $current_user_membership;
	}

	/**
	 * Execute condition to check if EDD product was purchased.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_edd_product_purchased( $condition ): bool {

		$compare    = $condition['compare'] ?? '==';
		$user_value = $condition['value'] ?? false;

		if ( ! $user_value || ! function_exists( 'EDD' ) ) {
			return true;
		}

		$current_user = get_current_user_id();
		$value        = intval( $user_value );

		return '==' === $compare ? edd_has_user_purchased( $current_user, $value ) : ! edd_has_user_purchased( $current_user, $value );
	}

	/**
	 * Execute condition to check if EDD product was purchased by ID.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_edd_product_purchased_id( $condition ): bool {

		$compare    = $condition['compare'] ?? '==';
		$user_value = bricks_render_dynamic_data( $condition['value'] ) ?? false;

		if ( ! $user_value || ! function_exists( 'EDD' ) ) {
			return true;
		}

		$current_user = get_current_user_id();
		$value        = intval( $user_value );

		return '==' === $compare ? edd_has_user_purchased( $current_user, $value ) : ! edd_has_user_purchased( $current_user, $value );
	}

	/**
	 * Execute condition to check if user is subscribed to EDD product.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_edd_subscribed( array $condition ): bool {

		if ( ! class_exists( '\EDD_Recurring_Subscriber' ) ) {
			return true;
		}

		$compare    = $condition['compare'] ?? '==';
		$user_value = $condition['value'] ?? false;

		if ( ! $user_value ) {
			return true;
		}

		$subscriber = new EDD_recurring_subscriber( get_current_user_id(), true );
		$value      = intval( $user_value );

		return '==' === $compare ? $subscriber->has_active_product_subscription( $value ) : ! $subscriber->has_active_product_subscription( $value );
	}

	/**
	 * Execute condition to check if user is subscribed to EDD product by ID.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_edd_subscribed_id( array $condition ): bool {

		if ( ! class_exists( '\EDD_Recurring_Subscriber' ) ) {
			return true;
		}

		$compare    = $condition['compare'] ?? '==';
		$user_value = bricks_render_dynamic_data( $condition['value'] ) ?? false;

		if ( ! $user_value ) {
			return true;
		}

		$subscriber = new EDD_recurring_subscriber( get_current_user_id(), true );
		$value      = intval( $user_value );

		return '==' === $compare ? $subscriber->has_active_product_subscription( $value ) : ! $subscriber->has_active_product_subscription( $value );
	}

	/**
	 * Execute condition to check WP Members membership.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_wp_members_membership( $condition ): bool {

		if ( ! class_exists( '\WP_Members_Products' ) ) {
			return true;
		}

		$compare    = $condition['compare'] ?? '==';
		$user_value = isset( $condition['value'] ) ? intval( bricks_render_dynamic_data( $condition['value'] ) ) : false;

		if ( ! $user_value ) {
			return true;
		}

		$product_slug = get_post_field( 'post_name', $user_value );

		return '==' === $compare ? wpmem_user_has_access( $product_slug ) : ! wpmem_user_has_access( $product_slug );
	}

	/**
	 * Execute condition to check RCP membership level.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_rcp_membership_level( $condition ): bool {

		if ( ! function_exists( 'rcp_get_membership_levels' ) ) {
			return true;
		}

		$compare    = $condition['compare'] ?? '==';
		$user_value = isset( $condition['value'] ) ? intval( bricks_render_dynamic_data( $condition['value'] ) ) : false;

		if ( ! $user_value ) {
			return true;
		}

		if ( '==' === $compare ) {
			// Note: RCP returns string IDs.
			$condition_met = in_array( $user_value, rcp_get_customer_membership_level_ids(), false );
		} elseif ( '!=' === $compare ) {
			$condition_met = ! in_array( $user_value, rcp_get_customer_membership_level_ids(), false );
		} else {

			$customer = rcp_get_customer_by_user_id( get_current_user_id() );

			if ( $customer ) {

				$args = array(
					'customer_id' => $customer->get_id(),
					'object_id'   => $user_value,
					'status'      => $compare,
				);

				$matching_memberships = rcp_get_memberships( $args );

				$condition_met = ! empty( $matching_memberships );

			} else {
				$condition_met = false;
			}
		}

		return $condition_met;
	}

	/**
	 * Execute condition to check if user has active RCP membership.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_rcp_has_active_membership( $condition ): bool {

		if ( ! function_exists( 'rcp_user_has_active_membership' ) ) {
			return true;
		}

		$user_value = $condition['value'] ?? 'true';

		return 'true' === $user_value ? rcp_user_has_active_membership() : ! rcp_user_has_active_membership();
	}

	/**
	 * Execute condition to check if user has paid RCP membership.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_rcp_has_paid_membership( $condition ): bool {

		if ( ! function_exists( 'rcp_user_has_paid_membership' ) ) {
			return true;
		}

		$user_value = $condition['value'] ?? 'true';

		return 'true' === $user_value ? rcp_user_has_paid_membership() : ! rcp_user_has_paid_membership();
	}

	/**
	 * Execute condition to check WishList Member membership.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_wishlist_member( $condition ): bool {

		$compare    = $condition['compare'] ?? '==';
		$user_value = bricks_render_dynamic_data( $condition['value'] ) ?? false;

		/* abort if no value */
		if ( ! $user_value || ! function_exists( 'wlmapi_get_levels' ) || ! function_exists( 'wlmapi_get_level_member_data' ) ) {
			return true;
		}

		$current_user_membership = wlmapi_is_user_a_member( intval( $user_value ), get_current_user_id() );

		switch ( $compare ) {

			case '==':
				$condition_met = $current_user_membership;
				break;

			case '!=':
				$condition_met = ! $current_user_membership;
				break;

			case 'active':
				if ( $current_user_membership ) {
					$membership_status = wlmapi_get_level_member_data( intval( $user_value ), get_current_user_id() )['member']['level']->Status[0];
					$condition_met     = 'Active' === $membership_status;
				} else {
					$condition_met = false;
				}

				break;

			case 'cancelled':
				if ( $current_user_membership ) {
					$membership_status = wlmapi_get_level_member_data( intval( $user_value ), get_current_user_id() )['member']['level']->Status[0];
					$condition_met     = 'Cancelled' === $membership_status;
				} else {
					$condition_met = false;
				}

				break;

			default:
				$condition_met = false;
				break;

		}

		return $condition_met;
	}

	/**
	 * Execute condition to check SureMembers access group.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_sure_members_access_groups( $condition ): bool {

		$compare    = $condition['compare'] ?? '==';
		$user_value = isset( $condition['value'] ) ? intval( bricks_render_dynamic_data( $condition['value'] ) ) : false;

		/* abort if no value */
		if ( ! $user_value || ! method_exists( '\SureMembers\Inc\Access_Groups', 'check_if_user_has_access' ) ) {
			return true;
		}

		$check_user_has_access = Access_Groups::check_if_user_has_access( (array) $user_value );

		return '==' === $compare ? $check_user_has_access : ! $check_user_has_access;
	}

	/**
	 * Execute condition to check Paid Memberships Pro membership level.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_pmp_membership_level( $condition ): bool {

		// If Paid Memberships Pro is not active, render the element.
		if ( ! class_exists( '\PMPro_Membership_Level' ) ) {
			return true;
		}

		$compare    = $condition['compare'] ?? '==';
		$user_value = bricks_render_dynamic_data( $condition['value'] ) ?? 'non-members';

		$has_membership_level = pmpro_hasMembershipLevel( $user_value );

		// Notes: https://d.pr/i/cHnYUV.

		$is_non_member = ! pmpro_hasMembershipLevel();

		if ( 'non-members' === $user_value ) {
			return '==' === $compare ? $is_non_member : ! $is_non_member;
		} else {
			return '==' === $compare ? $has_membership_level : ! $has_membership_level;
		}
	}

	/**
	 * Execute condition to check WooCommerce subscriptions.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_woocommerce_subscriptions( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = isset( $condition['value'] ) ? intval( bricks_render_dynamic_data( $condition['value'] ) ) : false;

		if ( ! $value || ! class_exists( '\WC_Subscriptions' ) || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$has_active_subscription = wcs_user_has_subscription( '', $value, 'active' );

		return '==' === $compare ? $has_active_subscription : ! $has_active_subscription;
	}

	/**
	 * Execute condition to check WooCommerce memberships.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_woocommerce_memberships( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = isset( $condition['value'] ) ? intval( bricks_render_dynamic_data( $condition['value'] ) ) : false;

		if ( ! $value || ! class_exists( '\WC_Memberships' ) || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$user_id = get_current_user_id();

		$has_active_membership = wc_memberships_is_user_active_member( $user_id, $value );

		return '==' === $compare ? $has_active_membership : ! $has_active_membership;
	}



	/* WooCommerce conditions */

	/**
	 * Execute condition to check if cart is empty.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_cart_empty( $condition ): bool {

		// If user value is empty, we set it to '' as default.
		$value = $condition['value'] ?? '';

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( ! WC()->cart ) {
			return true;
		}

		$is_empty = WC()->cart->is_empty();

		return 'empty' === $value ? $is_empty : ! $is_empty;
	}

	/**
	 * Execute condition to check if product is in cart.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_in_cart( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$product = wc_get_product( $value );

		if ( ! $product ) {
			return false; /* false if the product no longer exists. */
		}

		$product_type = $product->get_type();

		if ( ! WC()->cart ) {
			return true;
		}

		if ( 'variable' === $product_type ) {
			$in_cart = in_array( intval( $value ), array_column( WC()->cart->get_cart(), 'product_id' ), true );
		} else {
			$in_cart = WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id( $value ) );
		}

		return '==' === $compare ? $in_cart : ! $in_cart;
	}

	/**
	 * Execute condition to check if product is in cart by ID.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_in_cart_id( $condition ): bool {

		// If compare is empty, we set it to '==' as default.
		// If user value is empty, we set it to '' as default.
		$compare = $condition['compare'] ?? '==';
		$value   = bricks_render_dynamic_data( $condition['value'] ) ?? '';

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$product = wc_get_product( $value );

		if ( ! $product ) {
			return false; /* false if the product no longer exists. */
		}

		$product_type = $product->get_type();

		// Ensure session and cart are loaded for AJAX requests.
		if ( ! WC()->session ) {
			WC()->initialize_session();
		}

		if ( ! WC()->cart && function_exists( 'wc_load_cart' ) ) {
			wc_load_cart();
		}

		if ( ! WC()->cart ) {
			return '==' === $compare ? false : true;
		}

		$cart_contents = WC()->cart->get_cart();

		if ( 'variable' === $product_type ) {
			$in_cart = in_array( intval( $value ), array_column( $cart_contents, 'product_id' ), true );
		} else {
			$in_cart = WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id( $value ) );
		}

		return '==' === $compare ? $in_cart : ! $in_cart;
	}

	/**
	 * Execute condition to check if user purchased product.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_user_purchased_product( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? false;

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$has_purchased = wc_customer_bought_product( '', get_current_user_id(), $value );

		return '==' === $compare ? $has_purchased : ! $has_purchased;
	}

	/**
	 * Execute condition to check if user purchased product by ID.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_user_purchased_product_id( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = bricks_render_dynamic_data( $condition['value'] ) ?? false;

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$has_purchased = wc_customer_bought_product( '', get_current_user_id(), $value );

		return '==' === $compare ? $has_purchased : ! $has_purchased;
	}

	/**
	 * Execute condition to check if user just purchased product.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_user_just_purchased_product( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = bricks_render_dynamic_data( $condition['value'] ) ?? false;

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$order_id = 0;

		if ( is_wc_endpoint_url( 'order-received' ) ) {
			global $wp;
			$order_id = isset( $wp->query_vars['order-received'] ) ? absint( $wp->query_vars['order-received'] ) : 0;
		} elseif ( isset( $_GET['order_id'] ) && isset( $_GET['order_key'] ) ) {
			$order_id  = absint( Helpers::get_get_value( 'order_id' ) );
			$order_key = Helpers::get_get_value( 'order_key' );

			$order = wc_get_order( $order_id );
			if ( $order && $order->get_order_key() !== wc_clean( $order_key ) ) {
				$order_id = 0;
			}
		}

		if ( ! $order_id ) {
			return true;
		}

		$order = wc_get_order( $order_id );

		if ( ! $order ) {
			return true;
		}

		$just_purchased = false;

		foreach ( $order->get_items() as $item ) {
			if ( in_array( $item->get_product_id(), array( intval( $value ) ), true ) ) {
				$just_purchased = true;
				break;
			}
		}

		return $just_purchased;
	}

	/**
	 * Execute condition to check if user just purchased FluentCart product.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_user_just_purchased_fluentcart_product( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = bricks_render_dynamic_data( $condition['value'] ) ?? false;

		if ( ! $value || ! class_exists( '\FluentCart\App\Models\OrderTransaction' ) ) {
			return true;
		}

		$trx_hash = Helpers::get_get_value( 'trx_hash' ) ?? '';

		// Check if this is a FluentCart redirect with transaction hash.
		if ( ! $trx_hash ) {
			return false;
		}

		// Find transaction by UUID (trx_hash is the UUID).
		$transaction = \FluentCart\App\Models\OrderTransaction::where( 'uuid', $trx_hash )->first();

		if ( ! $transaction ) {
			return true;
		}

		// Get the order associated with this transaction.
		$order = $transaction->orders()->first();

		if ( ! $order ) {
			return true;
		}

		// Get order items to check for the target product.
		$order_items = $order->order_items()->get();

		$just_purchased = false;

		foreach ( $order_items as $item ) {
			if ( intval( $item->post_id ) === intval( $value ) ) {
				$just_purchased = true;
				break;
			}
		}

		return '==' === $compare ? $just_purchased : ! $just_purchased;
	}

	/**
	 * Execute condition to check cart total.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_cart_total( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 0;

		$value = bricks_render_dynamic_data( $value );

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( ! WC()->cart ) {
			return true;
		}

		$cart_total = WC()->cart->get_total( 'edit' );

		return self::get_maths_compare( $cart_total, floatval( $value ), $compare );
	}

	/**
	 * Execute condition to check cart total minus shipping.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_cart_total_minus_shipping( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 0;

		$value = bricks_render_dynamic_data( $value );

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( ! WC()->cart ) {
			return true;
		}

		$cart_total = WC()->cart->get_total( 'edit' ) - WC()->cart->get_shipping_total( 'edit' );

		return self::get_maths_compare( $cart_total, floatval( $value ), $compare );
	}

	/**
	 * Execute condition to check cart weight.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_cart_weight( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 0;

		$value = bricks_render_dynamic_data( $value );

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( ! WC()->cart ) {
			return true;
		}

		$cart_weight = WC()->cart->cart_contents_weight;

		return self::get_maths_compare( $cart_weight, floatval( $value ), $compare );
	}

	/**
	 * Execute condition to check if product is virtual.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_is_virtual( $condition ): bool {

		$value = $condition['value'] ?? 'true';

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_is_virtual = $product->is_virtual();

		return 'true' === $value ? $product_is_virtual : ! $product_is_virtual;
	}

	/**
	 * Execute condition to check if product is downloadable.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_is_downloadable( $condition ): bool {

		$value = $condition['value'] ?? 'true';

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_is_downloadable = $product->is_downloadable();

		return 'true' === $value ? $product_is_downloadable : ! $product_is_downloadable;
	}

	/**
	 * Execute condition to check if user purchased current product.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_user_purchased_current_product( $condition ): bool {

		$value = $condition['value'] ?? 'true';

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product          = new WC_Product( get_the_ID() );
			$product_id   = $product->get_id();
			$current_user = wp_get_current_user();

		$customer_bought_product = wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id );

		return 'true' === $value ? $customer_bought_product : ! $customer_bought_product;
	}

	/**
	 * Execute condition to check if user has pending order.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_user_has_pending_order( $condition ): bool {

		$value = $condition['value'] ?? 'true';

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$user = wp_get_current_user();

		if ( ! empty( $user ) ) {

			$customer_orders = get_posts(
				array(
					'numberposts' => -1,
					'meta_key'    => '_customer_user',
					'meta_value'  => $user->ID,
					'post_type'   => 'shop_order',
					'post_status' => 'wc-pending',
				)
			);

			$has_pending = count( $customer_orders ) > 0;

		} else {
			$has_pending = false;
		}

		return 'true' === $value ? $has_pending : ! $has_pending;
	}

	/**
	 * Execute condition to check if user has order with specific status.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_user_has_order_with_status( $condition ): bool {

		$value = $condition['value'] ?? 'wc-pending';

		if ( ! class_exists( '\WooCommerce' ) || ! function_exists( 'wc_get_orders' ) ) {
			return false;
		}

		$user = wp_get_current_user();

		if ( empty( $user ) || ! $user->ID ) {
			return false;
		}

		$customer_orders = wc_get_orders(
			array(
				'customer_id' => $user->ID,
				'status'      => str_replace( 'wc-', '', $value ),
				'limit'       => 1,
			)
		);

		return count( $customer_orders ) > 0;
	}

	/**
	 * Execute condition to check if product is in stock.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_in_stock( $condition ): bool {

		$value = $condition['value'] ?? 'true';

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_in_stock = $product->is_in_stock();

		return 'true' === $value ? $product_in_stock : ! $product_in_stock;
	}

	/**
	 * Execute condition to check product weight.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_weight( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 0;

		$value = bricks_render_dynamic_data( $value );

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_weight = $product->get_weight();

		return self::get_maths_compare( $product_weight, floatval( $value ), $compare );
	}

	/**
	 * Execute condition to check product rating.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_rating( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 0;

		$value = bricks_render_dynamic_data( $value );

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_rating = $product->get_average_rating();

		return self::get_maths_compare( floatval( $product_rating ), floatval( $value ), $compare );
	}

	/**
	 * Execute condition to check cart count.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_cart_count( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 0;

		$value = bricks_render_dynamic_data( $value );

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( ! WC()->cart ) {
			return true;
		}

		$cart_count = WC()->cart->get_cart_contents_count();

		return self::get_maths_compare( $cart_count, intval( $value ), $compare, false );
	}

	/**
	 * Execute condition to check product type.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_type( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? false;

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product_type = WC_Product_Factory::get_product_type( get_the_ID() );

		return '==' === $compare ? $value === $product_type : $value !== $product_type;
	}

	/**
	 * Execute condition to check if product is on backorder.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_on_backorder( $condition ): bool {

		$value = $condition['value'] ?? 'true';

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_on_backorder = $product->is_on_backorder();

		return 'true' === $value ? $product_on_backorder : ! $product_on_backorder;
	}

	/**
	 * Execute condition to check product upsell count.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_upsell_count( $condition ): bool {

		$compare = $condition['compare'] ?? '>';
		$value   = $condition['value'] ?? 0;

		$value = bricks_render_dynamic_data( $value );

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product              = new WC_Product( get_the_ID() );
		$product_upsell_count = count( $product->get_upsell_ids() );

		return self::get_maths_compare( $product_upsell_count, intval( $value ), $compare, false );
	}

	/**
	 * Execute condition to check product crosssells count.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_crosssells_count( $condition ): bool {

		$compare = $condition['compare'] ?? '>';
		$value   = $condition['value'] ?? 0;

		$value = bricks_render_dynamic_data( $value );

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_crosssells_count = count( $product->get_cross_sell_ids() );

		return self::get_maths_compare( $product_crosssells_count, intval( $value ), $compare, false );
	}

	/**
	 * Execute condition to check if product allows backorders.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_backorders_allowed( $condition ): bool {

		$value = $condition['value'] ?? 'true';

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_allows_backorder = $product->backorders_allowed();

		return 'true' === $value ? $product_allows_backorder : ! $product_allows_backorder;
	}

	/**
	 * Execute condition to check if product has category.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_has_category( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$has_term = has_term( $value, 'product_cat' );

		return '==' === $compare ? $has_term : ! $has_term;
	}

	/**
	 * Execute condition to check if product has tag.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_has_tag( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? '';

		if ( ! $value || ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		$has_term = has_term( $value, 'product_tag' );

		return '==' === $compare ? $has_term : ! $has_term;
	}

	/**
	 * Execute condition to check if current product is in cart.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_current_product_in_cart( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 'true';

		if ( ! class_exists( '\WooCommerce' ) ) {
			return true;
		}

		if ( 'product' !== get_post_type( get_the_ID() ) ) {
			return false;
		}

		$product = new WC_Product( get_the_ID() );

		$product_type = $product->get_type();

		// Ensure session and cart are loaded for AJAX requests.
		if ( ! WC()->session ) {
			WC()->initialize_session();
		}

		if ( ! WC()->cart && function_exists( 'wc_load_cart' ) ) {
			wc_load_cart();
		}

		if ( ! WC()->cart ) {
			return '==' === $compare ? false : true;
		}

		$cart_contents = WC()->cart->get_cart();

		if ( 'variable' === $product_type ) {
			$in_cart = in_array( get_the_ID(), array_column( $cart_contents, 'product_id' ), true );
		} else {
			$in_cart = WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id( get_the_ID() ) );
		}

		return 'true' === $value ? $in_cart : ! $in_cart;
	}

	/**
	 * Execute condition to check if product in cart has coupon.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_in_cart_has_coupon( $condition ): bool {
		$compare    = $condition['compare'] ?? '==';
		$product_id = isset( $condition['value'] ) ? intval( $condition['value'] ) : false;

		// Abort if no value or WooCommerce is not active.
		if ( ! $product_id || ! class_exists( '\WooCommerce' ) ) {
			return false;
		}

		// Get WooCommerce cart instance.
		$cart = WC()->cart;

		// Check if cart exists and has coupons.
		if ( empty( $cart ) || empty( $cart->get_applied_coupons() ) ) {
			return false;
		}

		// Get cart items.
		$cart_items = $cart->get_cart();

		// Loop through cart items to find our product.
		foreach ( $cart_items as $cart_item ) {
			if ( $cart_item['product_id'] === $product_id ) {
				// Get applied coupons.
				$applied_coupons = $cart->get_applied_coupons();

				foreach ( $applied_coupons as $coupon_code ) {
					$coupon = new \WC_Coupon( $coupon_code );

					// Check if coupon is valid for this product.
					$product_ids          = $coupon->get_product_ids();
					$excluded_product_ids = $coupon->get_excluded_product_ids();

					// If coupon has no specific products, it applies to all.
					if ( empty( $product_ids ) && ! in_array( $product_id, $excluded_product_ids, true ) ) {
						return true;
					}

					// If product is specifically included.
					if ( in_array( $product_id, $product_ids, true ) ) {
						return true;
					}
				}
			}
		}

		return false;
	}

	/**
	 * Execute condition to check if product in cart has coupon by ID.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_product_in_cart_has_coupon_id( $condition ): bool {
		$compare    = $condition['compare'] ?? '==';
		$product_id = isset( $condition['value'] ) ? intval( bricks_render_dynamic_data( $condition['value'] ) ) : false;

		// abort if no value or WooCommerce is not active.
		if ( ! $product_id || ! class_exists( '\WooCommerce' ) ) {
			return false;
		}

		// Get WooCommerce cart instance.
		$cart = WC()->cart;

		// Check if cart exists and has coupons.
		if ( empty( $cart ) || empty( $cart->get_applied_coupons() ) ) {
			return false;
		}

		// Get cart items.
		$cart_items = $cart->get_cart();

		// Loop through cart items to find our product.
		foreach ( $cart_items as $cart_item ) {
			if ( $cart_item['product_id'] === $product_id ) {
				// Get applied coupons.
				$applied_coupons = $cart->get_applied_coupons();

				foreach ( $applied_coupons as $coupon_code ) {
					$coupon = new \WC_Coupon( $coupon_code );

					// Check if coupon is valid for this product.
					$product_ids          = $coupon->get_product_ids();
					$excluded_product_ids = $coupon->get_excluded_product_ids();

					// If coupon has no specific products, it applies to all.
					if ( empty( $product_ids ) && ! in_array( $product_id, $excluded_product_ids, true ) ) {
						return true;
					}

					// If product is specifically included.
					if ( in_array( $product_id, $product_ids, true ) ) {
						return true;
					}
				}
			}
		}

		return false;
	}


	/**
	 * Execute condition to check if FluentCart user purchased product.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_fluentcart_user_purchased_product( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? false;

		if ( ! $value || ! class_exists( '\FluentCart\Api\Resource\CustomerResource' ) ) {
			return true;
		}

		// Get the current logged-in customer.
		$customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();

		if ( ! $customer ) {
			return '!=' === $compare ? true : false;
		}

		// Get all successful order items (products purchased).
		$purchased_items = $customer->success_order_items()
			->get();

		if ( $purchased_items->isEmpty() ) {
			return '!=' === $compare ? true : false;
		}

		// Check if the product ID exists in purchased items.
		$has_purchased = false;
		foreach ( $purchased_items as $item ) {
			if ( intval( $item->post_id ) === intval( $value ) ) {
				$has_purchased = true;
				break;
			}
		}

		return '==' === $compare ? $has_purchased : ! $has_purchased;
	}

	/**
	 * Execute condition to check if user purchased FluentCart product by ID.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_fluentcart_user_purchased_product_id( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = bricks_render_dynamic_data( $condition['value'] ) ?? false;

		if ( ! $value || ! class_exists( '\FluentCart\Api\Resource\CustomerResource' ) ) {
			return true;
		}

		// Get the current logged-in customer.
		$customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();

		if ( ! $customer ) {
			return '!=' === $compare ? true : false;
		}

		// Get all successful order items (products purchased).
		$purchased_items = $customer->success_order_items()
			->get();

		if ( $purchased_items->isEmpty() ) {
			return '!=' === $compare ? true : false;
		}

		// Check if the product ID exists in purchased items.
		$has_purchased = false;
		foreach ( $purchased_items as $item ) {
			if ( intval( $item->post_id ) === intval( $value ) ) {
				$has_purchased = true;
				break;
			}
		}

		return '==' === $compare ? $has_purchased : ! $has_purchased;
	}

	/**
	 * Execute condition to check FluentCart user subscription.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_fluentcart_user_subscription( $condition ): bool {

		$compare = $condition['compare'] ?? 'active';
		$value   = $condition['value'] ?? false;

		if ( ! $value || ! class_exists( '\FluentCart\Api\Resource\CustomerResource' ) ) {
			return true;
		}

		// Get the current logged-in customer.
		$customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();

		if ( ! $customer ) {
			return '!=' === $compare ? true : false;
		}

		if ( '!=' === $compare ) {

			$subscriptions = $customer->subscriptions()
				->where( 'product_id', intval( $value ) )
				->get();

			return $subscriptions->isEmpty();
		}

		// Get subscriptions with specific status for this customer and product.
		$subscriptions = $customer->subscriptions()
			->where( 'status', $compare )
			->where( 'product_id', intval( $value ) )
			->get();

		return ! $subscriptions->isEmpty();
	}

	/**
	 * Execute condition to check FluentCart user subscription by ID.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_fluentcart_user_subscription_id( $condition ): bool {

		$compare = $condition['compare'] ?? 'active';
		$value   = bricks_render_dynamic_data( $condition['value'] ) ?? false;

		if ( ! $value || ! class_exists( '\FluentCart\Api\Resource\CustomerResource' ) ) {
			return true;
		}

		// Get the current logged-in customer.
		$customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();

		if ( ! $customer ) {
			return '!=' === $compare ? true : false;
		}

		if ( '!=' === $compare ) {
			$subscriptions = $customer->subscriptions()
				->where( 'product_id', intval( $value ) )
				->get();
			return $subscriptions->isEmpty();
		}

		// Get subscriptions with specific status for this customer and product.
		$subscriptions = $customer->subscriptions()
			->where( 'status', $compare )
			->where( 'product_id', intval( $value ) )
			->get();

		return ! $subscriptions->isEmpty();
	}

	/**
	 * Execute condition to check if FluentCart user has any subscription.
	 *
	 * @param array $condition The condition configuration.
	 * @return bool True if condition is met, false otherwise.
	 */
	public static function execute_x_fluentcart_user_has_any_subscription( $condition ): bool {

		$compare = $condition['compare'] ?? '==';
		$value   = $condition['value'] ?? 'active';

		if ( ! class_exists( '\FluentCart\Api\Resource\CustomerResource' ) ) {
			return true;
		}

		// Get the current logged-in customer.
		$customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();

		if ( ! $customer ) {
			return '!=' === $compare ? true : false;
		}

		if ( 'any' === $value ) {
			$subscriptions    = $customer->subscriptions()->get();
			$has_subscription = ! $subscriptions->isEmpty();
			return '==' === $compare ? $has_subscription : ! $has_subscription;
		}

		// Get subscriptions with specific status for this customer (any product).
		$subscriptions = $customer->subscriptions()
			->where( 'status', $value )
			->get();

		$has_subscription = ! $subscriptions->isEmpty();
		return '==' === $compare ? $has_subscription : ! $has_subscription;
	}
}
