> 0 ) { foreach ( $tags as &$tag ) { $tag['tag'] = "[oxygen data='phpfunction' function='wfocu_order_data' arguments='" . $tag['tag'] . "']"; if ( true === $get_id ) { $tag['id'] = $tag['tag']; } } } return $tags; } /** * Create facebook advanced matching data * * @return mixed|null */ public static function pixel_advanced_matching_data() { $args = array(); if ( ! class_exists( 'BWF_Admin_General_Settings' ) ) { return $args; } $advanced_tracking = BWF_Admin_General_Settings::get_instance()->get_option( 'is_fb_advanced_event' ); if ( ! is_array( $advanced_tracking ) || count( $advanced_tracking ) === 0 || 'yes' !== $advanced_tracking[0] ) { return $args; } $params = self::advanced_matching_data(); if ( ! is_array( $params ) || 0 === count( $params ) ) { return $args; } foreach ( $params as $key => &$value ) { if ( ! empty( $value ) ) { $params[ $key ] = self::sanitize_advanced_matching_param( $value, $key ); } } return $params; } /** * Create tiktok advanced matching data * * @return mixed|null */ public static function tiktok_advanced_matching_data() { $args = array(); $params = self::advanced_matching_data(); if ( ! is_array( $params ) || 0 === count( $params ) ) { return $args; } // Normalize and hash email // Normalize and hash email if ( isset( $params['em'] ) && '' !== $params['em'] ) { if ( class_exists( 'WFFN_Common' ) && method_exists( 'WFFN_Common', 'normalize_tiktok_email' ) ) { $normalized_email = WFFN_Common::normalize_tiktok_email( $params['em'] ); if ( false !== $normalized_email ) { $args['sha256_email'] = hash( 'sha256', $normalized_email ); } } else { // Fallback to original behavior if normalization not available $args['sha256_email'] = hash( 'sha256', $params['em'] ); } } // Normalize and hash phone if ( isset( $params['ph'] ) && '' !== $params['ph'] ) { $country_code = ''; if ( class_exists( 'WooCommerce' ) && isset( $params['country'] ) ) { $country_code = $params['country']; } if ( class_exists( 'WFFN_Common' ) && method_exists( 'WFFN_Common', 'normalize_tiktok_phone' ) ) { $normalized_phone = WFFN_Common::normalize_tiktok_phone( $params['ph'], $country_code ); if ( false !== $normalized_phone ) { $args['sha256_phone_number'] = hash( 'sha256', $normalized_phone ); } } else { // Fallback to original behavior if normalization not available $args['sha256_phone_number'] = hash( 'sha256', $params['ph'] ); } } return $args; } public static function advanced_matching_data() { try { $params = array(); $user = wp_get_current_user(); if ( ! empty( $user ) && $user->ID !== 0 ) { // get user regular data $params['fn'] = $user->get( 'user_firstname' ); $params['ln'] = $user->get( 'user_lastname' ); $params['em'] = $user->get( 'user_email' ); $params['ph'] = get_user_meta( $user->ID, 'user_phone', true ); $params['external_id'] = $user->ID; } /** * Add common WooCommerce Advanced Matching params */ if ( class_exists( 'woocommerce' ) ) { if ( ! empty( $user ) && $user->ID !== 0 ) { if ( empty( $params['fn'] ) ) { $params['fn'] = $user->get( 'billing_first_name' ); } if ( empty( $params['ln'] ) ) { $params['ln'] = $user->get( 'billing_last_name' ); } $params['ph'] = $user->get( 'billing_phone' ); $params['ct'] = $user->get( 'billing_city' ); $params['st'] = $user->get( 'billing_state' ); $params['country'] = $user->get( 'billing_country' ); } } $params = apply_filters( 'wfocu_advanced_matching_data', $params ); if ( empty( $params['external_id'] ) && ! empty( $_COOKIE['wffn_flt'] ) ) { $params['external_id'] = bwf_clean( wp_unslash( $_COOKIE['wffn_flt'] ) ); //phpcs:ignore WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___COOKIE } if ( ! is_array( $params ) || count( $params ) === 0 ) { return array(); } return $params; } catch ( \Throwable $e ) { return array(); } } public static function sanitize_advanced_matching_param( $value, $key ) { $value = strtolower( $value ); if ( $key === 'ph' ) { $value = preg_replace( '/\D/', '', $value ); } elseif ( $key === 'em' ) { $value = preg_replace( '/[^a-z0-9._+-@]+/i', '', $value ); } else { // only letters with unicode support $value = preg_replace( '/[^\w\p{L}]/u', '', $value ); } return $value; } /** * Remove action for without instance method class found and return object of class * * @param $hook * @param $cls string * @param string $function * * @return |null */ public static function remove_actions( $hook, $cls, $function = '' ) { global $wp_filter; $object = null; if ( class_exists( $cls ) && isset( $wp_filter[ $hook ] ) && ( $wp_filter[ $hook ] instanceof WP_Hook ) ) { $hooks = $wp_filter[ $hook ]->callbacks; foreach ( $hooks as $priority => $reference ) { if ( is_array( $reference ) && count( $reference ) > 0 ) { foreach ( $reference as $index => $calls ) { if ( isset( $calls['function'] ) && is_array( $calls['function'] ) && count( $calls['function'] ) > 0 ) { if ( is_object( $calls['function'][0] ) ) { $cls_name = get_class( $calls['function'][0] ); if ( $cls_name === $cls && $calls['function'][1] === $function ) { $object = $calls['function'][0]; unset( $wp_filter[ $hook ]->callbacks[ $priority ][ $index ] ); } } elseif ( $index === $cls . '::' . $function ) { $object = $cls; unset( $wp_filter[ $hook ]->callbacks[ $priority ][ $cls . '::' . $function ] ); } } } } } } elseif ( function_exists( $cls ) && isset( $wp_filter[ $hook ] ) && ( $wp_filter[ $hook ] instanceof WP_Hook ) ) { $hooks = $wp_filter[ $hook ]->callbacks; foreach ( $hooks as $priority => $reference ) { if ( is_array( $reference ) && count( $reference ) > 0 ) { foreach ( $reference as $index => $calls ) { $remove = false; if ( $index === $cls ) { $remove = true; } elseif ( isset( $calls['function'] ) && $cls === $calls['function'] ) { $remove = true; } if ( true === $remove ) { unset( $wp_filter[ $hook ]->callbacks[ $priority ][ $cls ] ); } } } } } return $object; } public static function is_hpos_enabled() { return ( class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) && method_exists( '\Automattic\WooCommerce\Utilities\OrderUtil', 'custom_orders_table_usage_is_enabled' ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ); } public static function get_order_meta( $order, $key = '', $force = true ) { if ( empty( $key ) ) { return ''; } if ( ! $order instanceof WC_Abstract_Order ) { return ''; } $meta_value = $order->get_meta( $key ); if ( ! empty( $meta_value ) ) { return $meta_value; } if ( ! $force ) { return $meta_value; } if ( true === self::is_hpos_enabled() ) { global $wpdb; $meta_value = $wpdb->get_var( $wpdb->prepare( "SELECT `meta_value` FROM `{$wpdb->prefix}wc_orders_meta` WHERE `meta_key`=%s AND `order_id`=%d", $key, $order->get_id() ) ); } if ( ! empty( $meta_value ) ) { return maybe_unserialize( $meta_value ); } return get_post_meta( $order->get_id(), $key, true ); } public static function wc_get_orders( $args, $meta = array() ) { global $wpdb; $args = wp_parse_args( $args, array( 'post_type' => 'shop_order', ) ); $where = array( '1=1' ); if ( self::is_hpos_enabled() ) { $order_table = $wpdb->prefix . 'wc_orders'; $order_meta_table = $wpdb->prefix . 'wc_orders_meta'; $where[] = "AND type='" . esc_sql( $args['post_type'] ) . "'"; $sql_query = "SELECT orders.id as ID FROM {$order_table} as orders"; if ( ! empty( $meta ) ) { $sql_query .= " JOIN {$order_meta_table} as meta ON orders.id=meta.order_id"; } if ( isset( $args['status'] ) ) { if ( is_array( $args['status'] ) ) { $args['status'] = array_map( function ( $s ) { return 'wc-' . $s; }, $args['status'] ); $stasuses_in = implode( ',', array_map( function ( $s ) { return "'" . esc_sql( $s ) . "'"; }, $args['status'] ) ); $where[] = "AND orders.status IN ({$stasuses_in})"; } else { $stasuses_in = 'wc-' . $args['status']; $where[] = "AND orders.status = '" . esc_sql( $stasuses_in ) . "'"; } } if ( isset( $args['customer'] ) ) { $where[] = "AND orders.billing_email= '" . esc_sql( $args['customer'] ) . "'"; } $order = ' order by orders.date_created_gmt desc'; } else { $order_table = $wpdb->posts; $order_meta_table = $wpdb->postmeta; $where[] = "AND orders.post_type='" . esc_sql( $args['post_type'] ) . "'"; $sql_query = "SELECT orders.ID as ID FROM {$order_table} as orders"; if ( isset( $args['status'] ) ) { if ( is_array( $args['status'] ) ) { $args['status'] = array_map( function ( $s ) { return 'wc-' . $s; }, $args['status'] ); $stasuses_in = implode( ',', array_map( function ( $s ) { return "'" . esc_sql( $s ) . "'"; }, $args['status'] ) ); $where[] = "AND orders.post_status IN ({$stasuses_in})"; } else { $stasuses_in = 'wc-' . $args['status']; $where[] = "AND orders.post_status = '" . esc_sql( $stasuses_in ) . "'"; } } $order = ' order by orders.post_date_gmt desc'; if ( isset( $args['customer'] ) ) { $meta = array( 'key' => '_billing_email', 'value' => $args['customer'], ); } if ( ! empty( $meta ) ) { $sql_query .= " JOIN {$order_meta_table} as meta ON orders.ID=meta.post_id"; } } if ( ! empty( $meta ) ) { if ( isset( $meta['key'] ) ) { $where[] = "AND meta.meta_key = '" . esc_sql( $meta['key'] ) . "'"; } if ( isset( $meta['value'] ) ) { $operator = $meta['operator'] ?? '='; $operator = in_array( $operator, array( '=', '!=', '<', '>', '<=', '>=', 'LIKE' ), true ) ? $operator : '='; if ( true === $meta['value'] ) {// Specical Handling $operator = '!='; $meta['value'] = ''; } $where[] = "AND meta.meta_value {$operator} '" . esc_sql( $meta['value'] ) . "'"; } } $sql_query .= ' where ' . implode( ' ', $where ); $sql_query .= ' ' . $order; $limit = absint( $args['limit'] ?? 100 ); $paged = absint( $args['paged'] ?? 0 ); $offset = absint( $args['offset'] ?? 0 ); $paged = ( $paged > 0 ) ? ( $paged - 1 ) : $paged; if ( isset( $args['offset'] ) ) { $sql_query .= ' LIMIT ' . $offset . ', ' . $limit; } else { $sql_query .= ' LIMIT ' . $limit * $paged . ', ' . $limit; } $result = $wpdb->get_results( $sql_query, ARRAY_A ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared if ( empty( $result ) ) { return array(); } if ( isset( $args['return'] ) && 'ids' == $args['return'] ) { //phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison , Universal.Operators.StrictComparisons.LooseEqual return array_map( function ( $item ) { return $item['ID']; }, $result ); } return array_map( function ( $item ) { return wc_get_order( $item['ID'] ); }, $result ); } public static function oxy_get_meta_prefix( $key ) { if ( function_exists( 'oxy_get_meta_prefix' ) ) { $key = oxy_get_meta_prefix( $key ); } return $key; } /** * Get the version of the specified page builder plugin. * * For all the builder funnel builder support for templates, * we need to return the current version of the builder plugin from this method. * * @param string $builder The builder name (elementor, divi, or oxy). * @return string The builder version, or empty string if not found or on error. */ public static function get_builder_version( $builder ) { try { if ( $builder === 'elementor' ) { return ELEMENTOR_VERSION; } if ( $builder === 'divi' || $builder === 'divi5' ) { return defined( 'ET_BUILDER_PRODUCT_VERSION' ) ? ET_BUILDER_PRODUCT_VERSION : ''; } if ( $builder === 'oxy' ) { return CT_VERSION; } } catch ( Throwable $e ) { // Silently fail to prevent breaking main functionality } return ''; } } }