PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.13
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.13
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 / Types / WooCommerceSales.php

WooCommerceSales.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.13, at includes/Types/WooCommerceSales.php

437 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Extension Abstract
4 *
5 * @package NotificationX\Extensions
6 */
7
8 namespace NotificationX\Types;
9
10 use NotificationX\Core\Rules;
11 use NotificationX\Types\Traits\Conversions;
12 use NotificationX\Types\Traits\Reviews;
13 use NotificationX\Extensions\GlobalFields;
14 use NotificationX\GetInstance;
15 use NotificationX\NotificationX;
16
17 /**
18 * Extension Abstract for all Extension.
19 * @method static WooCommerce get_instance($args = null)
20 */
21 class WooCommerceSales extends Types {
22 /**
23 * Instance of Admin
24 *
25 * @var Admin
26 */
27 use GetInstance;
28 use Reviews;
29 use Conversions;
30
31 // colored_themes
32 public $priority = 5;
33 public $themes = [];
34 public $res_themes = [];
35 public $module = [
36 'modules_woocommerce',
37 'modules_woocommerce_sales_reviews',
38 'modules_woocommerce_sales_inline',
39 ];
40
41 public $map_dependency = [];
42
43 public $default_source = 'woocommerce_sales';
44 // public $default_theme = 'woocommerce_theme-one';
45 public $link_type = 'product_page';
46
47 /**
48 * Initially Invoked when initialized.
49 */
50 public function __construct(){
51 parent::__construct();
52 $this->id = 'woocommerce_sales';
53 }
54
55 public function init() {
56 parent::init();
57 $this->title = __('WooCommerce', 'notificationx');
58
59 $is_pro = ! NotificationX::is_pro();
60 // nx_colored_themes
61 $common_fields = [
62 'first_param' => 'tag_name',
63 'custom_first_param' => __('Someone' , 'notificationx'),
64 'second_param' => __('just purchased', 'notificationx'),
65 'third_param' => 'tag_product_title',
66 'custom_third_param' => __('Anonymous Product', 'notificationx'),
67 'fourth_param' => 'tag_time',
68 'custom_fourth_param' => __( 'Some time ago', 'notificationx' ),
69 ];
70 // Theme order mirrors includes/Types/Conversions.php so the Sales
71 // Notification and WooCommerce theme grids stay in sync.
72 $this->themes = [
73 'theme-one' => [
74 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-2.jpg',
75 'image_shape' => 'square',
76 'template' => $common_fields,
77 ],
78 // Figma "theme-one" — circular avatar, name row, action+product+time row,
79 // green "Verified by NotificationX" badge (branding) + right-aligned "Buy now" link.
80 'conv-theme-twelve' => array(
81 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-12.png',
82 'image_shape' => 'circle',
83 'template' => $common_fields,
84 'defaults' => [
85 'link_button' => true,
86 'link_button_text' => __( 'Buy now', 'notificationx' ),
87 ],
88 ),
89 // Figma "theme-two" — floating "Buy now" pill above top-right, rounded-square
90 // avatar, row 1 = name + right-aligned time, row 2 = "Bought <product>",
91 // green "Verified by NotificationX" badge.
92 'conv-theme-thirteen' => array(
93 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-13.png',
94 'image_shape' => 'rounded',
95 // Row 2 reads "Bought <product>" per the design (the shared default
96 // is "just purchased"), so override the action verb for this theme.
97 'template' => array_merge( $common_fields, [
98 'second_param' => __( 'Bought', 'notificationx' ),
99 ] ),
100 'defaults' => [
101 'link_button' => true,
102 'link_button_text' => __( 'Buy now', 'notificationx' ),
103 ],
104 ),
105 // Figma "theme-four" — left lavender image panel with a check badge, floating
106 // "Buy now" pill above top-right, row 1 = time (top-right), row 2 = name +
107 // action + product, green "Verified by NotificationX" badge.
108 'conv-theme-fifteen' => array(
109 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-15.png',
110 'image_shape' => 'rounded',
111 'template' => $common_fields,
112 'defaults' => [
113 'link_button' => true,
114 'link_button_text' => __( 'Buy now', 'notificationx' ),
115 ],
116 ),
117 'theme-two' => [
118 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-1.jpg',
119 'image_shape' => 'square',
120 'template' => $common_fields,
121 ],
122 'theme-three' => [
123 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-3.jpg',
124 'image_shape' => 'square',
125 'template' => $common_fields,
126 ],
127 'theme-five' => array(
128 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-five.png',
129 'image_shape' => 'circle',
130 'template' => $common_fields,
131 ),
132 'theme-four' => array(
133 'is_pro' => true,
134 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-four.png',
135 'image_shape' => 'circle',
136 'template' => $common_fields,
137 ),
138 // @todo pro map theme
139 'conv-theme-six' => array(
140 'is_pro' => true,
141 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-6.jpg',
142 'image_shape' => 'circle',
143 ),
144 // @todo pro map theme
145 'maps_theme' => array(
146 'is_pro' => true,
147 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/maps-theme.png',
148 'image_shape' => 'square',
149 'show_notification_image' => 'maps_image',
150 ),
151 'conv-theme-ten' => array(
152 'is_pro' => true,
153 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-4.png',
154 'image_shape' => 'rounded',
155 'defaults' => [
156 'link_button' => true,
157 ],
158 'template' => $common_fields,
159 ),
160 'conv-theme-eleven' => array(
161 'is_pro' => true,
162 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-5.png',
163 'image_shape' => 'rounded',
164 'defaults' => [
165 'link_button' => true,
166 ],
167 'template' => $common_fields,
168 ),
169 // Figma "theme-three" — sales-count card (cart icon, "X Buyers purchased /
170 // in last N days / Purchase now" + verified badge). Pro aggregates the count.
171 'conv-theme-fourteen' => array(
172 'is_pro' => true,
173 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-14.png',
174 'image_shape' => 'rounded',
175 'defaults' => [
176 'link_button' => true,
177 'link_button_text' => __( 'Purchase now', 'notificationx' ),
178 ],
179 ),
180 // Figma "theme-five" — sales-count card, alternate layout (badge on top,
181 // blue cart box, floating "Purchase now" pill). Same Pro count engine.
182 'conv-theme-sixteen' => array(
183 'is_pro' => true,
184 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-16.png',
185 'image_shape' => 'rounded',
186 'defaults' => [
187 'link_button' => true,
188 'link_button_text' => __( 'Purchase now', 'notificationx' ),
189 ],
190 ),
191 'conv-theme-seven' => array(
192 'is_pro' => true,
193 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-7.png',
194 'image_shape' => 'rounded',
195 ),
196 'conv-theme-eight' => array(
197 'is_pro' => true,
198 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-8.png',
199 'image_shape' => 'circle',
200
201 ),
202 'conv-theme-nine' => array(
203 'is_pro' => true,
204 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-9.png',
205 'image_shape' => 'rounded',
206 ),
207 ];
208 $this->res_themes = [
209 'res-theme-one' => [
210 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-1.png',
211 '_template' => 'woo_template_new',
212 'is_pro' => true,
213 ],
214 'res-theme-two' => [
215 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-2.png',
216 '_template' => 'woo_template_new',
217 'is_pro' => true,
218 ],
219 'res-theme-three' => [
220 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-3.png',
221 '_template' => 'woo_template_new',
222 'is_pro' => true,
223 ],
224 'res-theme-four' => [
225 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-4.png',
226 '_template' => 'woo_template_new',
227 'is_pro' => true,
228 ],
229 'res-theme-five' => [
230 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-5.png',
231 '_template' => 'maps_template_new',
232 'is_pro' => true,
233 ],
234 'res-theme-six' => [
235 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-6.png',
236 '_template' => 'maps_template_new',
237 'is_pro' => true,
238 ],
239 'res-theme-seven' => [
240 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-7.png',
241 '_template' => 'woo_template_new',
242 'is_pro' => true,
243 ],
244 'res-theme-eight' => [
245 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-8.png',
246 '_template' => 'woo_template_new',
247 'is_pro' => true,
248 ],
249 'res-theme-nine' => [
250 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-9.png',
251 '_template' => 'woo_template_sales_count',
252 'is_pro' => true,
253 ],
254 'res-theme-ten' => [
255 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-10.png',
256 '_template' => 'woo_template_sales_count',
257 'is_pro' => true,
258 ],
259 'res-theme-eleven' => [
260 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-11.png',
261 '_template' => 'woo_template_sales_count',
262 'is_pro' => true,
263 ],
264 ];
265 $this->templates = [
266 'woo_template_new' => [
267 'first_param' => GlobalFields::get_instance()->common_name_fields(),
268 'third_param' => [
269 'tag_product_title' => __('Product Title', 'notificationx'),
270 ],
271 'fourth_param' => [
272 'tag_time' => __('Definite Time', 'notificationx'),
273 ],
274 '_themes' => [
275 'woocommerce_sales_theme-one',
276 'woocommerce_sales_theme-two',
277 'woocommerce_sales_theme-three',
278 'woocommerce_sales_theme-four',
279 'woocommerce_sales_theme-five',
280 'woocommerce_sales_conv-theme-ten',
281 'woocommerce_sales_conv-theme-eleven',
282 'woocommerce_sales_conv-theme-twelve',
283 'woocommerce_sales_conv-theme-thirteen',
284 'woocommerce_sales_conv-theme-fifteen',
285 ]
286 ],
287 'woo_template_sales_count' => [
288 'first_param' => GlobalFields::get_instance()->common_name_fields(),
289 'third_param' => [
290 'tag_product_title' => __('Product Title', 'notificationx'),
291 ],
292 'fourth_param' => [
293 // 'tag_time' => __('Definite Time', 'notificationx'),
294 ],
295 '_themes' => [
296 'woocommerce_sales_conv-theme-six',
297 'woocommerce_sales_conv-theme-seven',
298 'woocommerce_sales_conv-theme-eight',
299 'woocommerce_sales_conv-theme-nine',
300 'woocommerce_sales_conv-theme-fourteen',
301 'woocommerce_sales_conv-theme-sixteen',
302 ]
303 ],
304 ];
305 add_filter("nx_filtered_entry_{$this->id}", array($this, 'conversion_data'), 11, 2);
306 }
307
308 /**
309 * Hooked to nx_before_metabox_load action.
310 *
311 * @return void
312 */
313 public function init_fields() {
314 parent::init_fields();
315 add_filter('nx_notification_template', [$this, 'review_templates'], 7);
316 add_filter('nx_content_trim_length_dependency', [$this, 'content_trim_length_dependency']);
317 }
318
319
320 /**
321 * @todo remove in the future.
322 *
323 * @param [type] $data
324 * @param [type] $settings
325 * @return void
326 */
327 public function nx_can_entry($return, $entry, $settings){
328 if(!($this->_excludes_product($entry['data'], $settings) && $this->_show_purchaseof($entry['data'], $settings))){
329 return false;
330 }
331
332 return $return;
333 }
334
335 /**
336 * @todo remove in the future.
337 *
338 * @param [type] $data
339 * @param [type] $settings
340 * @return void
341 */
342 public function show_exclude_product( $data, $settings ){
343 $new_data = [];
344
345 if( ! empty( $data ) ) {
346 foreach( $data as $key => $product ) {
347 if( $this->_excludes_product($product, $settings) && $this->_show_purchaseof($product, $settings) ) {
348 $new_data[ $key ] = $product;
349 }
350 }
351 }
352
353 return $new_data;
354
355 }
356
357 public function _excludes_product( $product, $settings ){
358 if( empty( $settings['product_exclude_by'] ) || $settings['product_exclude_by'] === 'none' ) {
359 return true;
360 }
361
362 $product_category_list = [];
363
364 $product_id = $product['product_id'];
365 if( $settings['product_exclude_by'] == 'product_category' ) {
366 $term = 'product_cat';
367 if($settings['source'] == 'edd' || $settings['source'] == 'edd_inline'){
368 $term = 'download_category';
369 }
370 $product_categories = get_the_terms( $product_id, $term );
371 if( ! is_wp_error( $product_categories ) ) {
372 foreach( $product_categories as $category ) {
373 $product_category_list[] = $category->slug;
374 }
375 }
376
377 $product_category_count = count( $product_category_list );
378 $array_diff = array_diff( $product_category_list, $settings['exclude_categories'] );
379 $array_diff_count = count( $array_diff );
380
381 if( ! ( $array_diff_count < $product_category_count ) ) {
382 return true;
383 }
384 $product_category_list = [];
385 }
386 if( $settings['product_exclude_by'] == 'manual_selection' ) {
387 if( isset($settings['exclude_products']) && is_array($settings['exclude_products']) && ! in_array( $product_id, $settings['exclude_products'] ) ) {
388 return true;
389 }
390 }
391
392 return false;
393
394 }
395
396
397 public function _show_purchaseof( $product, $settings ){
398 if( empty( $settings['product_control'] ) || $settings['product_control'] === 'none' ) {
399 return true;
400 }
401
402 $product_category_list = [];
403
404 $product_id = $product['product_id'];
405 if( $settings['product_control'] == 'product_category' ) {
406 $term = 'product_cat';
407 if($settings['source'] == 'edd' || $settings['source'] == 'edd_inline'){
408 $term = 'download_category';
409 }
410 $product_categories = get_the_terms( $product_id, $term );
411 if(is_array($product_categories) && ! is_wp_error( $product_categories ) ) {
412 foreach( $product_categories as $category ) {
413 $product_category_list[] = $category->slug;
414 }
415 }
416
417 $product_category_count = count( $product_category_list );
418 $array_diff = array_diff( $product_category_list, $settings['category_list'] );
419 $array_diff_count = count( $array_diff );
420
421 if( $array_diff_count < $product_category_count ) {
422 return true;
423 }
424
425 }
426 if( $settings['product_control'] == 'manual_selection' ) {
427 if( in_array( $product_id, $settings['product_list'] ) ) {
428 return true;
429 }
430 }
431
432 return false;
433 }
434
435
436 }
437