| 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 |
if ( ! sellkit()->has_valid_dependencies() ) { |
| 27 |
return []; |
| 28 |
} |
| 29 |
|
| 30 |
$filtered_products = []; |
| 31 |
$args = [ |
| 32 |
'post_type' => 'product', |
| 33 |
'post_status' => 'any', |
| 34 |
's' => $input_value, |
| 35 |
]; |
| 36 |
|
| 37 |
$query = new \WP_Query( $args ); |
| 38 |
|
| 39 |
if ( $query->have_posts() ) { |
| 40 |
while ( $query->have_posts() ) { |
| 41 |
$query->the_post(); |
| 42 |
$filtered_products[ get_the_ID() ] = html_entity_decode( get_the_title() ); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
return $filtered_products; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Gets the products categories. |
| 51 |
* |
| 52 |
* @since 1.1.0 |
| 53 |
* @param string $taxonomy The taxonomy. |
| 54 |
* @param string $input_value The input value. |
| 55 |
*/ |
| 56 |
function sellkit_get_terms( $taxonomy, $input_value ) { |
| 57 |
if ( ! sellkit()->has_valid_dependencies() ) { |
| 58 |
return []; |
| 59 |
} |
| 60 |
|
| 61 |
$filtered_terms = []; |
| 62 |
|
| 63 |
$args = array( |
| 64 |
'taxonomy' => $taxonomy, |
| 65 |
'number' => 20, |
| 66 |
'orderby' => 'ID', |
| 67 |
'order' => 'DESC', |
| 68 |
'hide_empty' => false, |
| 69 |
'name__like' => $input_value, |
| 70 |
); |
| 71 |
|
| 72 |
$terms = get_terms( $args ); |
| 73 |
|
| 74 |
foreach ( $terms as $term ) { |
| 75 |
$filtered_terms[ $term->term_id ] = $term->name; |
| 76 |
} |
| 77 |
|
| 78 |
return $filtered_terms; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Sellkit filter array based on a specific string. |
| 83 |
* |
| 84 |
* @since 1.1.0 |
| 85 |
* @param array $array Array of data. |
| 86 |
* @param string $string Required string. |
| 87 |
*/ |
| 88 |
function sellkit_filter_array( $array, $string ) { |
| 89 |
return array_filter( $array, function ( $country ) use ( $string ) { |
| 90 |
return strpos( strtolower( $country ), strtolower( $string ) ) !== false; |
| 91 |
} ); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Gets Ip. |
| 96 |
* |
| 97 |
* @since 1.1.0 |
| 98 |
* @return string |
| 99 |
* phpcs:disable WordPress.Security.ValidatedSanitizedInput |
| 100 |
*/ |
| 101 |
function sellkit_get_ip() { |
| 102 |
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
| 103 |
return $_SERVER['HTTP_CLIENT_IP']; |
| 104 |
} |
| 105 |
|
| 106 |
if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
| 107 |
return $_SERVER['HTTP_X_FORWARDED_FOR']; |
| 108 |
} |
| 109 |
|
| 110 |
return $_SERVER['REMOTE_ADDR']; |
| 111 |
} |
| 112 |
|