PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.2.9
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.2.9
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / contact-segmentation / functions.php

functions.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.2.9, at includes/contact-segmentation/functions.php

104 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Sellkit\Contact_Segmentation\Conditions;
4
5 /**
6 * Condition match wrapper.
7 *
8 * @since 1.1.0
9 * @param string $condition_name Condition name.
10 * @param string $operator_name Condition operator.
11 * @param mixed $condition_value Condition value.
12 */
13 function sellkit_condition_match( $condition_name, $operator_name, $condition_value ) {
14 $condition_value = apply_filters( "sellkit_cs_conditions_value_{$condition_name}", $condition_value );
15
16 return Conditions::match( $condition_name, $operator_name, $condition_value );
17 }
18
19 /**
20 * Get all of the products, it's searchable.
21 *
22 * @since 1.1.0
23 * @param string $input_value The input value for searching.
24 */
25 function sellkit_get_products( $input_value ) {
26 $filtered_products = [];
27 $args = [
28 'post_type' => 'product',
29 'post_status' => 'any',
30 's' => $input_value,
31 ];
32
33 $query = new \WP_Query( $args );
34
35 if ( $query->have_posts() ) {
36 while ( $query->have_posts() ) {
37 $query->the_post();
38 $filtered_products[ get_the_ID() ] = html_entity_decode( get_the_title() );
39 }
40 }
41
42 return $filtered_products;
43 }
44
45 /**
46 * Gets the products categories.
47 *
48 * @since 1.1.0
49 * @param string $taxonomy The taxonomy.
50 * @param string $input_value The input value.
51 */
52 function sellkit_get_terms( $taxonomy, $input_value ) {
53 $filtered_terms = [];
54
55 $args = array(
56 'taxonomy' => $taxonomy,
57 'number' => 20,
58 'orderby' => 'ID',
59 'order' => 'DESC',
60 'hide_empty' => false,
61 'name__like' => $input_value,
62 );
63
64 $terms = get_terms( $args );
65
66 foreach ( $terms as $term ) {
67 $filtered_terms[ $term->term_id ] = $term->name;
68 }
69
70 return $filtered_terms;
71 }
72
73 /**
74 * Sellkit filter array based on a specific string.
75 *
76 * @since 1.1.0
77 * @param array $array Array of data.
78 * @param string $string Required string.
79 */
80 function sellkit_filter_array( $array, $string ) {
81 return array_filter( $array, function ( $country ) use ( $string ) {
82 return strpos( strtolower( $country ), strtolower( $string ) ) !== false;
83 } );
84 }
85
86 /**
87 * Gets Ip.
88 *
89 * @since 1.1.0
90 * @return string
91 * phpcs:disable WordPress.Security.ValidatedSanitizedInput
92 */
93 function sellkit_get_ip() {
94 if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
95 return $_SERVER['HTTP_CLIENT_IP'];
96 }
97
98 if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
99 return $_SERVER['HTTP_X_FORWARDED_FOR'];
100 }
101
102 return $_SERVER['REMOTE_ADDR'];
103 }
104