PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / trunk
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar vtrunk
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Extensions / WooCommerce / Woo.php

Woo.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar trunk, at includes/Extensions/WooCommerce/Woo.php

66 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WooCommerce Extension
4 *
5 * @package NotificationX\Extensions
6 */
7
8 namespace NotificationX\Extensions\WooCommerce;
9
10 use NotificationX\Core\Helper;
11 use NotificationX\Core\Rules;
12 use NotificationX\Extensions\GlobalFields;
13
14 trait Woo {
15 public $post_type = 'product';
16
17
18 public function _init_fields(){
19 add_filter('nx_conversion_product_list', [$this, 'products']);
20 add_filter('nx_conversion_category_list', [$this, 'categories']);
21 }
22
23
24 public function categories($options){
25
26 $product_categories = get_terms(array(
27 'taxonomy' => 'product_cat',
28 'hide_empty' => false,
29 ));
30
31 $category_list = [];
32
33 if( ! is_wp_error( $product_categories ) ) {
34 foreach( $product_categories as $product ) {
35 $category_list[ $product->slug ] = $product->name;
36 }
37 }
38
39 $options = GlobalFields::get_instance()->normalize_fields($category_list, 'source', $this->id, $options);
40 return $options;
41 }
42
43 public function products($options){
44 $product_list = Helper::get_post_titles_by_search($this->post_type);
45 $options = GlobalFields::get_instance()->normalize_fields($product_list, 'source', $this->id, $options);
46 return $options;
47 }
48
49 /**
50 * Lists available tags in the selected form.
51 *
52 * @param array $args An array of arguments, including inputValue.
53 * @return array An indexed array of product IDs and titles.
54 */
55 public function restResponse($args) {
56 // Check if inputValue is provided
57 if ( empty( $args['search_empty']) && empty($args['inputValue'] ) ) {
58 return [];
59 }
60 // Get the products that match the inputValue
61 $products = Helper::get_post_titles_by_search($this->post_type, $args['inputValue']);
62 // Normalize the fields and return as an indexed array
63 return array_values(GlobalFields::get_instance()->normalize_fields($products, 'source', $this->id));
64 }
65
66 }