| 1 |
<?php |
| 2 |
/** |
| 3 |
* Reviews Types |
| 4 |
* |
| 5 |
* @package NotificationX\Types |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace NotificationX\Types\Traits; |
| 9 |
use NotificationX\Core\Rules; |
| 10 |
|
| 11 |
trait Conversions { |
| 12 |
|
| 13 |
public function excludes_product( $data, $settings ){ |
| 14 |
if( empty( $settings['product_exclude_by'] ) || $settings['product_exclude_by'] === 'none' ) { |
| 15 |
return $data; |
| 16 |
} |
| 17 |
$product_category_list = $new_data = []; |
| 18 |
|
| 19 |
if( ! empty( $data ) ) { |
| 20 |
foreach( $data as $key => $product ) { |
| 21 |
$product_id = $product['product_id']; |
| 22 |
if( $settings['product_exclude_by'] == 'product_category' ) { |
| 23 |
$product_categories = get_the_terms( $product_id, 'product_cat' ); |
| 24 |
if( ! is_wp_error( $product_categories ) ) { |
| 25 |
foreach( $product_categories as $category ) { |
| 26 |
$product_category_list[] = $category->slug; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
$product_category_count = count( $product_category_list ); |
| 31 |
$array_diff = array_diff( $product_category_list, $settings['exclude_categories'] ); |
| 32 |
$array_diff_count = count( $array_diff ); |
| 33 |
|
| 34 |
if( ! ( $array_diff_count < $product_category_count ) ) { |
| 35 |
$new_data[ $key ] = $product; |
| 36 |
} |
| 37 |
$product_category_list = []; |
| 38 |
} |
| 39 |
if( $settings['product_exclude_by'] == 'manual_selection' ) { |
| 40 |
if( ! in_array( $product_id, $settings['exclude_products'] ) ) { |
| 41 |
$new_data[ $key ] = $product; |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
return $new_data; |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
public function show_purchaseof( $data, $settings ){ |
| 52 |
if( empty( $settings['product_control'] ) || $settings['product_control'] === 'none' ) { |
| 53 |
return $data; |
| 54 |
} |
| 55 |
|
| 56 |
$product_category_list = $new_data = []; |
| 57 |
|
| 58 |
if( ! empty( $data ) ) { |
| 59 |
foreach( $data as $key => $product ) { |
| 60 |
$product_id = $product['product_id']; |
| 61 |
if( $settings['product_control'] == 'product_category' ) { |
| 62 |
$product_categories = get_the_terms( $product_id, 'product_cat' ); |
| 63 |
if( ! is_wp_error( $product_categories ) ) { |
| 64 |
foreach( $product_categories as $category ) { |
| 65 |
$product_category_list[] = $category->slug; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
$product_category_count = count( $product_category_list ); |
| 70 |
$array_diff = array_diff( $settings['category_list'], $product_category_list ); |
| 71 |
$array_diff_count = count( $array_diff ); |
| 72 |
|
| 73 |
$cute_logic = ( count( $settings['category_list'] ) - ( $product_category_count + $array_diff_count) ); |
| 74 |
|
| 75 |
if( ! $cute_logic ) { |
| 76 |
$new_data[ $key ] = $product; |
| 77 |
} |
| 78 |
$product_category_list = []; |
| 79 |
} |
| 80 |
if( $settings['product_control'] == 'manual_selection' ) { |
| 81 |
if( in_array( $product_id, $settings['product_list'] ) ) { |
| 82 |
$new_data[ $key ] = $product; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
return $new_data; |
| 88 |
} |
| 89 |
|
| 90 |
} |