PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.1.9
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.1.9
1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 All 178 releases
disco / app / DropDown / DropDown.php

DropDown.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.1.9, at app/DropDown/DropDown.php

642 lines 22.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore
2 namespace Disco\App\DropDown;
3
4 /**
5 * Class DropDown
6 *
7 * @package CTXFeed
8 * @subpackage app\DropDown
9 * @author Ohidul Islam <wahid0003@gmail.com>
10 * @link https://webappick.com
11 * @license https://opensource.org/licenses/gpl-license.php GNU Public License
12 * @category MyCategory
13 */
14 class DropDown { // phpcs:ignore
15
16 /**
17 * Conditions.
18 *
19 * @param string $type Condition Type to compare. Acceptable values:
20 * 'string' string type conditions
21 * 'number' number type conditions
22 * 'date' date type conditions
23 * 'select' list type conditions.
24 * @param string|array $key Condition Key to get specific condition.
25 * @return array
26 */
27 public static function conditions( $type = null, $key = null ) { // phpcs:ignore
28 $condition = array(
29 'equal' => 'Equal',
30 'not_equal' => 'Not Equal',
31 'contain' => 'Contain',
32 'not_contain' => 'Does Not Contain',
33 'start_with' => 'Start With',
34 'end_with' => 'End With',
35 'greater' => 'Greater Than',
36 'greater_equal' => 'Greater Than or Equal',
37 'lesser' => 'Less Than',
38 'lesser_equal' => 'Less Than or Equal',
39 'between' => 'Between',
40 'date_between' => 'Date Between',
41 // 'within_past' => 'Within Past',
42 // 'earlier_than' => 'Earlier Than',
43 'in_list' => 'In List',
44 'not_in_list' => 'Not In List',
45 );
46
47 if ( 'string' === $type ) {
48 unset(
49 $condition['in_list'],
50 $condition['not_in_list'],
51 $condition['greater'],
52 $condition['greater_equal'],
53 $condition['lesser'],
54 $condition['lesser_equal'],
55 $condition['between'],
56 $condition['date_between']
57 );
58 }
59
60 if ( 'number' === $type ) {
61 unset(
62 $condition['in_list'],
63 $condition['not_in_list'],
64 $condition['date_between'],
65 $condition['start_with'],
66 $condition['end_with'],
67 $condition['contain'],
68 $condition['not_contain']
69 );
70 }
71
72 if ( 'select' === $type ) {
73 if ( isset( $key['multiple'] ) && $key['multiple'] === false ) {
74 unset(
75 $condition['contain'],
76 $condition['not_contain'],
77 $condition['in_list'],
78 $condition['not_in_list'],
79 $condition['greater'],
80 $condition['greater_equal'],
81 $condition['lesser'],
82 $condition['lesser_equal'],
83 $condition['between'],
84 $condition['date_between'],
85 $condition['start_with'],
86 $condition['end_with']
87 );
88 } else {
89 unset(
90 $condition['contain'],
91 $condition['not_contain'],
92 $condition['equal'],
93 $condition['not_equal'],
94 $condition['greater'],
95 $condition['greater_equal'],
96 $condition['lesser'],
97 $condition['lesser_equal'],
98 $condition['between'],
99 $condition['date_between'],
100 $condition['start_with'],
101 $condition['end_with']
102 );
103 }
104 }
105
106 if ( 'date' === $type ) {
107 unset(
108 $condition['in_list'],
109 $condition['not_in_list'],
110 $condition['contain'],
111 $condition['not_contain'],
112 $condition['start_with'],
113 $condition['end_with'],
114 $condition['between']
115 );
116 }
117
118 if ( is_array( $condition ) ) {
119 return $condition;
120 }
121
122 return array();
123 }
124
125 /**
126 * Prepare Filters for frontend appearance.
127 *
128 * @param string $title Filter Title.
129 *
130 * @param string $condition_type Condition Type to compare. Acceptable values:
131 * 'string' string type conditions
132 * 'number' number type conditions
133 * 'date' date type conditions
134 * 'date' date type conditions
135 * 'select' list type conditions.
136 *
137 * @param string|array $input_type Input Filed for compare value. Acceptable values:
138 * 'text' for input[type=text]
139 * 'number' for input[type=number]
140 * 'date' for input[type=datetime-local]
141 *
142 * For 'select' dropdown, there are two options available:
143 *
144 * For manual options:
145 * [
146 * 'type' => 'select',
147 * 'option_type' => 'manual',
148 * 'multiple' => true,
149 * 'options' => ['key' => 'value']
150 * ]
151 * OR For api options:
152 * [
153 * 'type' => 'select',
154 * 'option_type' => 'api',
155 * 'multiple' => true,
156 * 'endpoint' => 'https://example.com/api/endpoint'
157 * ].
158 *
159 * @param string $component Component to load into frontend. Acceptable values:
160 * 'string' for string type conditions
161 * 'number' for number type conditions
162 * 'date' for date type conditions
163 * 'select' for list type conditions.
164 * @return array Filter Array
165 * [0]=>[
166 * [optionGroup] => Filter Group Title,
167 * [options] => [
168 * 'attribute' => [ // Attribute key to compare with. Example: 'id',
169 * 'title', 'sku'.
170 * 'title' => 'Filter Title',
171 * 'component' => 'string',
172 * 'condition' => [available conditions from self::Conditions()]
173 * 'input_type' => 'text',
174 * 'fields' => [
175 * 'compare' => '',
176 * 'condition' => '',
177 * 'compare_with' => '',
178 * 'operator' => '',
179 * ]
180 * ]
181 * ]
182 * ].
183 */
184 public static function prepare_filters(
185 $title,
186 $condition_type = 'string',
187 $input_type = 'text',
188 $component = 'string'
189 ) {
190 $fields = array(
191 'compare' => '',
192 'condition' => '',
193 'compare_with' => '',
194 'operator' => '',
195 );
196
197 return array(
198 'title' => $title,// phpcs:ignore
199 'component' => $component,
200 'condition' => self::Conditions( $condition_type, $input_type ),
201 'input_type' => $input_type, // Input Filed Type. Example values -> HTML Input Type
202 'fields' => $fields,
203 );
204 }
205
206 /**
207 * Get All Filters.
208 * Check the phpdoc comments of prepare_filters() method for details.
209 *
210 * @return array
211 * @throws \Exception If the search term is not set.
212 */
213 public static function filters() { // phpcs:ignore
214 $filter_attributes = array();
215
216 $primary_attributes = array(
217 'optionGroup' => __( 'Product/Cart Item', 'disco' ),
218 'options' => array(
219 'id' => self::prepare_filters( 'ID', 'number', 'number' ),
220 'sku' => self::prepare_filters( 'SKU' ),
221 'title' => self::prepare_filters( 'Title' ),
222 'description' => self::prepare_filters( 'Description' ),
223 'short_description' => self::prepare_filters( 'Short Description' ),
224 'attributes' => self::prepare_filters(
225 'Attributes',
226 'select',
227 array(
228 'type' => 'select',
229 'option_type' => 'api',
230 'multiple' => true,
231 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/attribute/?search=' ),
232 )
233 ),
234 'categories' => self::prepare_filters(
235 'Categories',
236 'select',
237 array(
238 'type' => 'select',
239 'option_type' => 'api',
240 'multiple' => true,
241 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/category/?search=' ),
242 )
243 ),
244 'tags' => self::prepare_filters(
245 'Tags',
246 'select',
247 array(
248 'type' => 'select',
249 'option_type' => 'api',
250 'multiple' => true,
251 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/tag/?search=' ),
252 )
253 ),
254 'link' => self::prepare_filters( 'URL' ),
255 'availability' => self::prepare_filters( 'Availability' ),
256 'quantity' => self::prepare_filters( 'Quantity', 'number', 'number' ),
257 'stock_status' => self::prepare_filters(
258 'Stock Status',
259 'select',
260 array(
261 'type' => 'select',
262 'option_type' => 'manual',
263 'multiple' => true,
264 'options' => wc_get_product_stock_status_options(),
265 )
266 ),
267 'weight' => self::prepare_filters( 'Weight', 'number', 'number' ),
268 'weight_unit' => self::prepare_filters(
269 'Weight Unit',
270 'select',
271 array(
272 'type' => 'select',
273 'option_type' => 'manual',
274 'multiple' => true,
275 'options' => array(
276 'kg' => esc_html__( 'kg', 'disco' ),
277 'g' => esc_html__( 'g', 'disco' ),
278 'lb' => esc_html__( 'lb', 'disco' ),
279 'oz' => esc_html__( 'oz', 'disco' ),
280 ),
281 )
282 ),
283 'width' => self::prepare_filters( 'Width', 'number', 'number' ),
284 'height' => self::prepare_filters( 'Height', 'number', 'number' ),
285 'length' => self::prepare_filters( 'Length', 'number', 'number' ),
286 'type' => self::prepare_filters(
287 'Product Type',
288 'select',
289 array(
290 'type' => 'select',
291 'option_type' => 'manual',
292 'multiple' => true,
293 'options' => wc_get_product_types(),
294 )
295 ),
296 'visibility' => self::prepare_filters(
297 'Visibility',
298 'select',
299 array(
300 'type' => 'select',
301 'option_type' => 'manual',
302 'multiple' => true,
303 'options' => wc_get_product_visibility_options(),
304 )
305 ),
306 'rating_total' => self::prepare_filters( 'Total Rating', 'number', 'number' ),
307 'rating_average' => self::prepare_filters( 'Average Rating', 'number', 'number' ),
308 'author_name' => self::prepare_filters(
309 'Author Name',
310 'select',
311 array(
312 'type' => 'select',
313 'option_type' => 'api',
314 'multiple' => true,
315 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/customer/?search=' ),
316 )
317 ),
318 'author_email' => self::prepare_filters(
319 'Author Email',
320 'select',
321 array(
322 'type' => 'select',
323 'option_type' => 'api',
324 'multiple' => true,
325 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/customer/?search=' ),
326 )
327 ),
328 'date_created' => self::prepare_filters( 'Date Created', 'date', 'date' ),
329 'date_updated' => self::prepare_filters( 'Date Updated', 'date', 'date' ),
330
331 'product_status' => self::prepare_filters(
332 'Status',
333 'select',
334 array(
335 'type' => 'select',
336 'option_type' => 'manual',
337 'multiple' => false,
338 'options' => array(
339 'publish' => esc_html__( 'Publish', 'disco' ),
340 'draft' => esc_html__( 'Draft', 'disco' ),
341 'pending' => esc_html__( 'Pending', 'disco' ),
342 'private' => esc_html__( 'Private', 'disco' ),
343 ),
344 )
345 ),
346 'featured_status' => self::prepare_filters(
347 'Featured Status',
348 'select',
349 array(
350 'type' => 'select',
351 'option_type' => 'manual',
352 'multiple' => false,
353 'options' => array(
354 'yes' => esc_html__( 'Yes', 'disco' ),
355 'no' => esc_html__( 'No', 'disco' ),
356 ),
357 )
358 ),
359 ),
360 );
361 $filter_attributes[] = $primary_attributes;
362
363 $price_attributes = array(
364 'optionGroup' => esc_html__( 'Price', 'disco' ),
365 'options' => array(
366 'currency' => self::prepare_filters( 'Currency' ),
367 'regular_price' => self::prepare_filters( 'Regular Price', 'number', 'number' ),
368 'price' => self::prepare_filters( 'Price', 'number', 'number' ),
369 'sale_price' => self::prepare_filters( 'Sale Price', 'number', 'number' ),
370 'regular_price_with_tax' => self::prepare_filters( 'Regular Price With Tax', 'number', 'number' ),
371 'price_with_tax' => self::prepare_filters( 'Price With Tax', 'number', 'number' ),
372 'sale_price_with_tax' => self::prepare_filters( 'Sale Price With Tax', 'number', 'number' ),
373 'sale_price_sdate' => self::prepare_filters( 'Sale Start Date', 'date', 'date' ),
374 'sale_price_edate' => self::prepare_filters( 'Sale End Date', 'date', 'date' ),
375 ),
376 );
377
378 $filter_attributes[] = $price_attributes;
379
380 // Product Global Attributes
381 $filter_attributes[] = AttributeDropDown::get_global_attributes();
382
383
384 // Tax and Shipping Attributes
385 $tax_shipping = array(
386 'optionGroup' => esc_html__( 'Tax and Shipping', 'disco' ),
387 'options' => array(
388 'tax_class' => self::prepare_filters( 'Tax Class' ),
389 'tax_status' => self::prepare_filters( 'Tax Status' ),
390 'shipping_class' => self::prepare_filters( 'Shipping Class' ),
391 ),
392 );
393 $filter_attributes[] = $tax_shipping;
394
395 /**
396 * Subscription Attributes
397 * Add subscription attributes if WooCommerce Subscription plugin installed.
398 *
399 * @link https://woocommerce.com/products/woocommerce-subscriptions/
400 */
401 if ( class_exists( 'WC_Subscriptions' ) ) {
402 $subscription_attributes = array(
403 'optionGroup' => esc_html__( 'Subscription & Installment', 'disco' ),
404 'options' => array(
405 'subscription_period' => self::prepare_filters( 'Subscription Period' ),
406 'subscription_period_interval' => self::prepare_filters( 'Subscription Period Length' ),
407 'subscription_amount' => self::prepare_filters( 'Subscription Amount', 'number', 'number' ),
408 'installment_months' => self::prepare_filters( 'Installment Months', 'number', 'number' ),
409 'installment_amount' => self::prepare_filters( 'Installment Amount', 'number', 'number' ),
410 ),
411 );
412 // TODO: Move to premium version
413 // $filter_attributes[] = $subscription_attributes;
414 }
415
416 /**
417 * Unit Price (WooCommerce Germanized)
418 * Get Germanized for WooCommerce plugins unit attributes.
419 *
420 * @link https://wordpress.org/plugins/woocommerce-germanized/
421 */
422 if ( class_exists( 'WooCommerce_Germanized' ) ) {
423 $wc_unit_price_attributes = array(
424 'optionGroup' => esc_html__( 'Unit Price (WooCommerce Germanized)', 'disco' ),
425 'options' => array(
426 'wc_germanized_unit_price_measure' => self::prepare_filters( 'Unit Price Measure' ),
427 'wc_germanized_unit_price_base_measure' => self::prepare_filters( 'Unit Price Base Measure' ),
428 'wc_germanized_gtin' => self::prepare_filters( 'GTIN' ),
429 'wc_germanized_mpn' => self::prepare_filters( 'MPN' ),
430 ),
431 );
432
433 // TODO: Move to premium version
434 // $filter_attributes[] = $wc_unit_price_attributes;
435 }
436
437 // Cart Attributes
438 $cart_attributes = array(
439 'optionGroup' => esc_html__( 'Cart', 'disco' ),
440 'options' => array(
441 'cart_items_count' => self::prepare_filters( 'Cart Items Count', 'number', 'number' ),
442 'cart_items_quantity' => self::prepare_filters( 'Cart Items Quantity', 'number', 'number' ),
443 'cart_total_weight' => self::prepare_filters( 'Cart Items Total Weight', 'number', 'number' ),
444 'cart_subtotal' => self::prepare_filters( 'Cart Subtotal', 'number', 'number' ),
445 'cart_payment_method' => self::prepare_filters(
446 'Payment Method',
447 'select',
448 array(
449 'type' => 'select',
450 'option_type' => 'manual',
451 'multiple' => true,
452 'options' => StoreDropDown::payment_methods(),
453 )
454 ),
455 'cart_coupons' => self::prepare_filters(
456 'Cart Coupons',
457 'select',
458 array(
459 'type' => 'select',
460 'option_type' => 'api',
461 'multiple' => true,
462 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/coupon/?search=' ),
463 )
464 ),
465 ),
466 );
467
468 $filter_attributes[] = $cart_attributes;
469
470 $purchase_history_attributes = array(
471 'optionGroup' => esc_html__( 'Product Purchase History', 'disco' ),
472 'options' => array(
473 'product_history_last_order_date' => self::prepare_filters( 'Last Order Date', 'date', 'date' ),
474 'product_history_total_order_made' => self::prepare_filters(
475 'Number of Order Made with Following Products',
476 'select',
477 array(
478 'type' => 'select',
479 'option_type' => 'api',
480 'multiple' => true,
481 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/product/?search=' ),
482 )
483 ),
484 'product_history_total_amount_sold' => self::prepare_filters(
485 'Number of Amount Sold with Following Products',
486 'select',
487 array(
488 'type' => 'select',
489 'option_type' => 'api',
490 'multiple' => true,
491 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/product/?search=' ),
492 )
493 ),
494 'product_history_total_quantity_sold' => self::prepare_filters(
495 'Number of Quantities Sold with Following Products',
496 'select',
497 array(
498 'type' => 'select',
499 'option_type' => 'api',
500 'multiple' => true,
501 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/product/?search=' ),
502 )
503 ),
504 ),
505 );
506
507 // TODO: Move to premium version
508 // $filter_attributes[] = $purchase_history_attributes;
509
510 $customer_attributes = array(
511 'optionGroup' => esc_html__( 'Customer', 'disco' ),
512 'options' => array(
513 // 'customer_email' => self::prepare_filters(
514 // 'Email',
515 // 'select',
516 // array(
517 // 'type' => 'select',
518 // 'option_type' => 'api',
519 // 'multiple' => true,
520 // 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/customer/?search=' ),
521 // )
522 // ),
523 'customer_name' => self::prepare_filters(
524 'Customer',
525 'select',
526 array(
527 'type' => 'select',
528 'option_type' => 'api',
529 'multiple' => true,
530 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/customer/?search=' ),
531 )
532 ),
533 'customer_is_logged_in' => self::prepare_filters(
534 'Is Logged In',
535 'select',
536 array(
537 'type' => 'select',
538 'option_type' => 'manual',
539 'multiple' => false,
540 'options' => array(
541 'yes' => esc_html__( 'Yes', 'disco' ),
542 'no' => esc_html__( 'No', 'disco' ),
543 ),
544 )
545 ),
546 'customer_user_role' => self::prepare_filters(
547 'User Role',
548 'select',
549 array(
550 'type' => 'select',
551 'option_type' => 'manual',
552 'multiple' => true,
553 'options' => StoreDropDown::user_roles(),
554 )
555 ),
556 'customer_country' => self::prepare_filters(
557 'Country',
558 'select',
559 array(
560 'type' => 'select',
561 'option_type' => 'api',
562 'multiple' => true,
563 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/country/?search=' ),
564 )
565 ),
566 'customer_state' => self::prepare_filters(
567 'State',
568 'select',
569 array(
570 'type' => 'select',
571 'option_type' => 'api',
572 'multiple' => true,
573 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/state/?search=' ),
574 )
575 ),
576 'customer_zip' => self::prepare_filters( 'Zip' ),
577 ),
578 );
579
580 $filter_attributes[] = $customer_attributes;
581
582 $customer_order_history_attributes = array(
583 'optionGroup' => esc_html__( 'Customer Purchase History', 'disco' ),
584 'options' => array(
585 'customer_history_first_order' => self::prepare_filters(
586 'Is First Order',
587 'select',
588 array(
589 'type' => 'select',
590 'option_type' => 'manual',
591 'multiple' => false,
592 'options' => array(
593 'yes' => esc_html__( 'Yes', 'disco' ),
594 'no' => esc_html__( 'No', 'disco' ),
595 ),
596 )
597 ),
598 'customer_history_last_order_date' => self::prepare_filters( 'Last Order Date', 'date', 'date' ),
599 'customer_history_last_order_amount' => self::prepare_filters( 'Last Order Amount', 'number', 'number' ),
600 'customer_history_total_order_made' => self::prepare_filters( 'Number of Order Made By Customer', 'number', 'number' ),
601 'customer_history_total_amount_sold' => self::prepare_filters( 'Total Amount Spent By Customer', 'number', 'number' ),
602 'customer_history_total_quantity_sold' => self::prepare_filters( 'Total Quantities Bought By Customer', 'number', 'number' ),
603 'customer_history_total_order_made_by_ids' => self::prepare_filters(
604 'Number of Order Made with Following Products',
605 'select',
606 array(
607 'type' => 'select',
608 'option_type' => 'api',
609 'multiple' => true,
610 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/product/?search=' ),
611 )
612 ),
613 'customer_history_total_amount_sold_by_ids' => self::prepare_filters(
614 'Number of Amount Sold with Following Products',
615 'select',
616 array(
617 'type' => 'select',
618 'option_type' => 'api',
619 'multiple' => true,
620 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/product/?search=' ),
621 )
622 ),
623 'customer_history_total_quantity_sold_by_ids' => self::prepare_filters(
624 'Number of Quantities Sold with Following Products',
625 'select',
626 array(
627 'type' => 'select',
628 'option_type' => 'api',
629 'multiple' => true,
630 'endpoint' => get_site_url( null, '/wp-json/disco/v1/search/product/?search=' ),
631 )
632 ),
633 ),
634 );
635 // TODO: Move to premium version
636 // $filter_attributes[] = $customer_order_history_attributes;
637
638 return apply_filters( 'disco_filter_drop_down', $filter_attributes );
639 }
640
641 }
642