WooCommerce Advanced Free Shipping - Version 1.1.0

Version Description

  • 06-03-2017
Download this release

Release Info

Developer sormano
Plugin Icon 128x128 WooCommerce Advanced Free Shipping
Version 1.1.0
Comparing to
See all releases

Code changes from version 1.0.11 to 1.1.0

Files changed (56) hide show
  1. assets/css/woocommerce-advanced-free-shipping.min.css +1 -1
  2. assets/css/woocommerce-advanced-free-shipping.scss +1 -61
  3. assets/js/woocommerce-advanced-free-shipping.js +0 -104
  4. assets/js/woocommerce-advanced-free-shipping.min.js +0 -1
  5. codeoversight.yml +6 -2
  6. includes/admin/admin-functions.php +0 -100
  7. includes/admin/class-wafs-admin.php +9 -11
  8. includes/admin/class-wafs-condition.php +17 -164
  9. includes/admin/views/conditions-table.php +1 -1
  10. includes/admin/views/html-condition-group.php +39 -0
  11. includes/admin/views/html-condition-row.php +11 -11
  12. includes/admin/views/meta-box-conditions.php +10 -20
  13. includes/admin/views/meta-box-settings.php +0 -1
  14. includes/class-wafs-ajax.php +1 -81
  15. includes/class-wafs-match-conditions.php +0 -734
  16. includes/class-wafs-method.php +11 -72
  17. includes/class-wafs-post-type.php +19 -56
  18. includes/core-functions.php +53 -2
  19. libraries/wp-conditions/admin-functions.php +181 -0
  20. libraries/wp-conditions/assets/css/wp-conditions.min.css +1 -0
  21. {assets/css/parts → libraries/wp-conditions/assets/css}/wp-conditions.scss +116 -14
  22. libraries/wp-conditions/assets/js/repeater/jquery.repeater.js +57 -0
  23. libraries/wp-conditions/assets/js/repeater/jquery.repeater.min.js +1 -0
  24. libraries/wp-conditions/assets/js/wp-conditions.js +175 -0
  25. libraries/wp-conditions/assets/js/wp-conditions.min.js +1 -0
  26. libraries/wp-conditions/conditions/wpc-category-condition.php +74 -0
  27. libraries/wp-conditions/conditions/wpc-city-condition.php +66 -0
  28. libraries/wp-conditions/conditions/wpc-condition.php +123 -0
  29. libraries/wp-conditions/conditions/wpc-contains-category-condition.php +74 -0
  30. libraries/wp-conditions/conditions/wpc-contains-product-condition.php +78 -0
  31. libraries/wp-conditions/conditions/wpc-contains-shipping-class-condition.php +72 -0
  32. libraries/wp-conditions/conditions/wpc-country-condition.php +87 -0
  33. libraries/wp-conditions/conditions/wpc-coupon-condition.php +76 -0
  34. libraries/wp-conditions/conditions/wpc-date-condition.php +39 -0
  35. libraries/wp-conditions/conditions/wpc-day-condition.php +43 -0
  36. libraries/wp-conditions/conditions/wpc-fallback-condition.php +28 -0
  37. libraries/wp-conditions/conditions/wpc-height-condition.php +36 -0
  38. libraries/wp-conditions/conditions/wpc-length-condition.php +36 -0
  39. libraries/wp-conditions/conditions/wpc-page-condition.php +100 -0
  40. libraries/wp-conditions/conditions/wpc-payment-gateway-condition.php +48 -0
  41. libraries/wp-conditions/conditions/wpc-quantity-condition.php +33 -0
  42. libraries/wp-conditions/conditions/wpc-role-condition.php +64 -0
  43. libraries/wp-conditions/conditions/wpc-shipping-method-condition.php +134 -0
  44. libraries/wp-conditions/conditions/wpc-state-condition.php +59 -0
  45. libraries/wp-conditions/conditions/wpc-stock-condition.php +39 -0
  46. libraries/wp-conditions/conditions/wpc-stock-status-condition.php +74 -0
  47. libraries/wp-conditions/conditions/wpc-subtotal-condition.php +28 -0
  48. libraries/wp-conditions/conditions/wpc-subtotal-ex-tax-condition.php +27 -0
  49. libraries/wp-conditions/conditions/wpc-tax-condition.php +27 -0
  50. libraries/wp-conditions/conditions/wpc-time-condition.php +39 -0
  51. libraries/wp-conditions/conditions/wpc-weight-condition.php +28 -0
  52. libraries/wp-conditions/conditions/wpc-width-condition.php +36 -0
  53. libraries/wp-conditions/conditions/wpc-zipcode-condition.php +81 -0
  54. libraries/wp-conditions/functions.php +297 -0
  55. readme.txt +89 -42
  56. woocommerce-advanced-free-shipping.php +18 -14
assets/css/woocommerce-advanced-free-shipping.min.css CHANGED
@@ -1 +1 @@
1
- .wpc-conditions .wpc-condition-group{margin-bottom:30px;background-color:#f5f5f5;padding:15px 20px 20px;border:1px solid #ddd;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04);min-height:30px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap{margin:10px 0 5px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-condition{width:30%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-operator{width:12%;min-width:140px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-value{width:30%;height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description{float:right}.wpc-conditions .wpc-condition-group .wpc-condition-wrap input{vertical-align:top}.wpc-conditions .or-text{display:none !important}.wpc-conditions .wpc-condition-group ~ .or-text,.wpc-conditions .wpc-condition-group ~ .or-text ~ .wpc-condition-group .or-text{display:block !important}.wpc-conditions .wpc-condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wpc-conditions .wpc-condition-wrap:hover .wpc-condition-delete{display:inline-block;opacity:1}.wpc-conditions .wpc-condition-wrap.loading{height:30px}.wpc-conditions .wpc-condition-wrap.loading .loading-icon{width:100%;clear:both;display:block;text-align:center;line-height:110%;margin:0 1px}.wpc-condition-wrap .wpc-value.select2-container{display:inline-block !important;margin:1px}.wpc-condition-wrap .wpc-value.select2-container.select2-container-active .select2-choice{border:1px solid #666}.wpc-condition-wrap .wpc-value.select2-container.select2-drop-above .select2-choice{border-radius:0 0 4px 4px;border:1px solid #666;border-top-color:transparent}.wpc-condition-wrap .wpc-value.select2-container .select2-choice{border-color:#ddd;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;height:26px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07)}.wpc-condition-wrap .wpc-value.select2-dropdown-open .select2-choice{border-bottom-color:transparent;-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset;border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid #666;outline:0}.wpc-conditions-post-table .sort{padding:0 4px;cursor:move;text-align:center;vertical-align:middle}.wpc-conditions-post-table .sort:before{content:"\e032";font-family:WooCommerce;text-align:center;line-height:1;color:#999;display:block;width:100%;float:left;height:100%}.wpc-conditions-post-table .sort:before,.wpc-conditions-post-table .row-actions{visibility:hidden !important}.wpc-conditions-post-table tr:hover .sort:before,.wpc-conditions-post-table tr:hover>td>.row-actions{visibility:visible !important}.wpc-conditions-post-table .add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}.wpc-currency{padding:3px 10px;font-size:14px;font-weight:400;line-height:19px;height:27px;box-sizing:border-box;color:#555;text-align:center;background-color:#EEE;border:1px solid #DDD;border-right:none;border-radius:4px 0px 0px 4px;margin:1px 0px 1px 1px;display:inline-block}.wpc-currency+input{margin-left:-4px;line-height:19px;width:161px !important}.post-type-wafs .misc-pub-visibility#visibility{display:none}.wafs-option label{display:inline-block;width:150px}.wafs_conditions_meta_box>p:first-child+div>.or_match{display:none}.condition-group{margin-bottom:30px;background-color:#f5f5f5;padding:15px 20px 20px;border:1px solid #ddd;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04)}.wafs-condition-wrap{margin:10px 0px 5px}.wafs-condition-wrap .wafs-condition{width:30%}.wafs-condition-wrap .wafs-operator{width:12%;min-width:140px}.wafs-condition-wrap .wafs-value{width:30%}.wafs-condition-wrap input{vertical-align:top}#wafs_conditions p+p{display:none}.wafs_desc{display:none;position:absolute;background:rgba(0,0,0,0.8);min-width:25px;max-width:200px;border-radius:6px;padding:5px 10px;color:white;margin-top:10px;right:40px;text-align:center}.wafs_desc:after{border-top:0px solid transparent;border-right:10px solid transparent;border-left:10px solid transparent;border-bottom:10px solid rgba(0,0,0,0.8);content:' ';position:absolute;top:-10px;right:10px;z-index:999}.wafs_tip:hover ~ .wafs_desc{display:block !important}.wafs-description{width:40px;float:right;line-height:20px}.wafs-condition-wrap ~ .loading-icon{display:block}.loading-icon{width:30%;clear:both;display:inline-block;text-align:center;line-height:110%;margin:0 1px}.condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wafs-condition-wrap:hover .condition-delete{display:inline-block;opacity:1}.add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}#advanced_free_shipping_shipping_methods tr .row-actions{visibility:hidden}#advanced_free_shipping_shipping_methods tr:hover>td>.row-actions{visibility:visible !important}
1
+ .wpc-conditions .wpc-condition-group{background-color:#f5f5f5;padding:15px;border:1px solid #e5e5e5;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04);min-height:30px;margin:0 -13px 1.5em}.wpc-conditions .wpc-condition-group:hover .wpc-condition-group-actions{opacity:1}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions{opacity:0;margin:-10px -10px 0 0;font-size:80%}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a{text-decoration:none}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete{color:#a00}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete:hover{color:#f00}.wpc-conditions .wpc-condition-group .wpc-condition-wrap{margin:10px 0 5px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-condition{width:35%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-operator{width:22.5%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-value{width:calc( 42.5% - 75px );height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description{float:right}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip{height:28px;line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip:after{line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap input{vertical-align:top}.wpc-conditions .clearfix:after{content:" ";display:block;height:0;clear:both}.wpc-conditions .wpc-add.button:before{font-family:'dashicons';content:"\f502";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;margin-right:5px;color:#667}.wpc-conditions .wpc-condition-delete.button{font-weight:600;width:30px;text-align:center;padding:0}.wpc-conditions .wpc-condition-delete.button:before{font-family:'dashicons';content:"\f460";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;color:#667}.wpc-conditions>p+.wpc-condition-group-wrap p.or-text{display:none}.wpc-conditions .or-text{margin:1.5em 0}.wpc-conditions .match-text{margin:0 0 1em}.wpc-conditions .wpc-condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wpc-conditions .wpc-condition-wrap:hover .wpc-condition-delete{display:inline-block;opacity:1}.wpc-conditions .wpc-condition-wrap.loading{height:30px}.wpc-conditions .wpc-condition-wrap.loading .loading-icon{width:100%;clear:both;display:block;text-align:center;line-height:110%;margin:0 1px}.wpc-condition-wrap .wpc-value.select2-container{display:inline-block !important;margin:1px}.wpc-condition-wrap .wpc-value.select2-container.select2-container-active .select2-choice{border:1px solid #666}.wpc-condition-wrap .wpc-value.select2-container.select2-drop-above .select2-choice{border-radius:0 0 4px 4px;border:1px solid #666;border-top-color:transparent}.wpc-condition-wrap .wpc-value.select2-container .select2-choice{border-color:#ddd;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;height:26px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07)}.wpc-condition-wrap .wpc-value.select2-dropdown-open .select2-choice{border-bottom-color:transparent;-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset;border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid #666;outline:0}.wpc-condition-wrap .select2-container .select2-selection--single{height:28px !important}.wpc-condition-wrap .select2-container .select2-selection--single #select2--container,.wpc-condition-wrap .select2-container .select2-selection--single .select2-selection__arrow{line-height:26px}.wpc-condition-wrap .select2-container .select2-selection--single .select2-selection__arrow{height:28px}.wpc-conditions-post-table .sort{padding:0 4px;cursor:move;text-align:center;vertical-align:middle}.wpc-conditions-post-table .sort:before{content:"\e032";font-family:WooCommerce;text-align:center;line-height:1;color:#999;display:block;width:100%;float:left;height:100%}.wpc-conditions-post-table .sort:before,.wpc-conditions-post-table .row-actions{visibility:hidden !important}.wpc-conditions-post-table tr:hover .sort:before,.wpc-conditions-post-table tr:hover>td>.row-actions{visibility:visible !important}.wpc-conditions-post-table .add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}@media screen and (max-width: 782px){.wpc-conditions-post-table th{padding:8px}.wpc-conditions-post-table td{padding:8px 10px}.wpc-conditions-post-table tfoot .button{margin-bottom:0}}.wpc-currency{padding:3px 10px;font-size:14px;font-weight:400;line-height:19px;height:27px;box-sizing:border-box;color:#555;text-align:center;background-color:#EEE;border:1px solid #DDD;border-right:none;border-radius:4px 0px 0px 4px;margin:1px 0px 1px 1px;display:inline-block}.wpc-currency+input{margin-left:-4px;line-height:19px;width:161px !important}@media screen and (max-width: 782px){.wpc-currency{font-size:16px;padding:6px 10px;height:33px}}.post-type-wafs .misc-pub-visibility#visibility{display:none}.wafs-option label{display:inline-block;width:150px}.wafs_conditions_meta_box>p:first-child+div>.or_match{display:none}.wafs_desc{display:none;position:absolute;background:rgba(0,0,0,0.8);min-width:25px;max-width:200px;border-radius:6px;padding:5px 10px;color:white;margin-top:10px;right:40px;text-align:center}.wafs_desc:after{border-top:0px solid transparent;border-right:10px solid transparent;border-left:10px solid transparent;border-bottom:10px solid rgba(0,0,0,0.8);content:' ';position:absolute;top:-10px;right:10px;z-index:999}.wafs_tip:hover ~ .wafs_desc{display:block !important}.wafs-description{width:40px;float:right;line-height:20px}.condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wafs-condition-wrap:hover .condition-delete{display:inline-block;opacity:1}#advanced_free_shipping_shipping_methods tr .row-actions{visibility:hidden}#advanced_free_shipping_shipping_methods tr:hover>td>.row-actions{visibility:visible !important}
assets/css/woocommerce-advanced-free-shipping.scss CHANGED
@@ -1,4 +1,4 @@
1
- @import 'parts/wp-conditions';
2
 
3
  /* Hide visibility from admin */
4
  .post-type-wafs .misc-pub-visibility#visibility {
@@ -13,37 +13,7 @@
13
  .wafs_conditions_meta_box > p:first-child + div > .or_match {
14
  display: none;
15
  }
16
- /*
17
- * Condition group
18
- */
19
- .condition-group {
20
- margin-bottom: 30px;
21
- background-color: #f5f5f5;
22
- padding: 15px 20px 20px;
23
- border: 1px solid #ddd;
24
- -webkit-box-shadow: 0 1px 1px rgba( 0, 0, 0, .04);
25
- box-shadow: 0 1px 1px rgba( 0, 0, 0, .04);
26
- }
27
- .wafs-condition-wrap {
28
- margin: 10px 0px 5px;
29
- }
30
- .wafs-condition-wrap .wafs-condition {
31
- width: 30%;
32
- }
33
- .wafs-condition-wrap .wafs-operator {
34
- width: 12%;
35
- min-width: 140px;
36
- }
37
- .wafs-condition-wrap .wafs-value {
38
- width: 30%;
39
- }
40
- .wafs-condition-wrap input {
41
- vertical-align: top;
42
- }
43
 
44
- #wafs_conditions p + p {
45
- display: none;
46
- }
47
  /* Description */
48
  .wafs_desc {
49
  display: none;
@@ -78,23 +48,6 @@
78
  line-height: 20px;
79
  }
80
 
81
- /*
82
- * Loading icon
83
- */
84
-
85
- /* Load icon condition row */
86
- .wafs-condition-wrap ~ .loading-icon {
87
- display: block;
88
- }
89
- .loading-icon {
90
- width: 30%;
91
- clear: both;
92
- display: inline-block;
93
- text-align: center;
94
- line-height: 110%;
95
- margin: 0 1px;
96
- }
97
-
98
  .condition-delete {
99
  display: none;
100
  opacity: 0;
@@ -105,19 +58,6 @@
105
  opacity: 1;
106
  }
107
 
108
-
109
- /* WooCommerce Add icon */
110
- .add.button:before {
111
- font-family: WooCommerce;
112
- speak: none;
113
- font-weight: 400;
114
- font-variant: normal;
115
- text-transform: none;
116
- line-height: 1;
117
- -webkit-font-smoothing: antialiased;
118
- margin-right: 7px;
119
- content: "\e007";
120
- }
121
  /* Overview row actions */
122
  #advanced_free_shipping_shipping_methods tr .row-actions {
123
  visibility: hidden;
1
+ @import '../../libraries/wp-conditions/assets/css/wp-conditions';
2
 
3
  /* Hide visibility from admin */
4
  .post-type-wafs .misc-pub-visibility#visibility {
13
  .wafs_conditions_meta_box > p:first-child + div > .or_match {
14
  display: none;
15
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
 
 
 
17
  /* Description */
18
  .wafs_desc {
19
  display: none;
48
  line-height: 20px;
49
  }
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  .condition-delete {
52
  display: none;
53
  opacity: 0;
58
  opacity: 1;
59
  }
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  /* Overview row actions */
62
  #advanced_free_shipping_shipping_methods tr .row-actions {
63
  visibility: hidden;
assets/js/woocommerce-advanced-free-shipping.js DELETED
@@ -1,104 +0,0 @@
1
- jQuery( function( $ ) {
2
-
3
- /**************************************************************
4
- * WPC - 1.0.1
5
- *************************************************************/
6
-
7
- // Add condition
8
- $( document.body ).on( 'click', '.wpc-condition-add', function() {
9
-
10
- var $this = $( this );
11
- var data = {
12
- action: wpc.action_prefix + 'add_condition',
13
- group: $( this ).attr( 'data-group' ),
14
- nonce: wpc.nonce
15
- };
16
- var condition_group = $this.parents( '.wpc-conditions' ).find( '.wpc-condition-group-' + data.group );
17
-
18
- var loading_icon = '<div class="wpc-condition-wrap loading"></div>';
19
- condition_group.append( loading_icon ).children( ':last' ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } });
20
-
21
- $.post( ajaxurl, data, function( response ) {
22
- condition_group.find( ' .wpc-condition-wrap.loading' ).first().replaceWith( function() {
23
- return $( response ).hide().fadeIn( 'normal' );
24
- });
25
- });
26
-
27
- });
28
-
29
- // Delete condition
30
- $( document.body ).on( 'click', '.wpc-condition-delete', function() {
31
-
32
- if ( $( this ).closest( '.wpc-condition-group' ).children( '.wpc-condition-wrap' ).length == 1 ) {
33
- $( this ).closest( '.wpc-condition-group' ).fadeOut( 'normal', function() {
34
- $( this ).next( '.or-text' ).remove();
35
- $( this ).remove();
36
- });
37
- } else {
38
- $( this ).closest( '.wpc-condition-wrap' ).slideUp( 'fast', function() { $( this ).remove(); });
39
- }
40
-
41
- });
42
-
43
- // Add condition group
44
- $( document.body ).on( 'click', '.wpc-condition-group-add', function() {
45
-
46
- var condition_group_loading = '<div class="wpc-condition-group loading"></div>';
47
- var conditions = $( this ).prev( '.wpc-conditions' );
48
- var data = {
49
- action: wpc.action_prefix + 'add_condition_group',
50
- group: parseInt( $( this ).prev( '.wpc-conditions' ).find( '.wpc-condition-group' ).length ),
51
- nonce: wpc.nonce
52
- };
53
-
54
- // Display loading icon
55
- conditions.append( condition_group_loading ).children( ':last' ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } });
56
-
57
- // Insert condition group
58
- $.post( ajaxurl, data, function( response ) {
59
- conditions.find( '.wpc-condition-group.loading' ).first().replaceWith( function() {
60
- return $( response ).hide().fadeIn( 'normal' );
61
- });
62
- });
63
-
64
- });
65
-
66
- // Update condition values
67
- $( document.body ).on( 'change', '.wpc-condition', function () {
68
-
69
- var loading_wrap = '<span style="width: 30%; border: 1px solid transparent; display: inline-block;">&nbsp;</span>';
70
- var data = {
71
- action: wpc.action_prefix + 'update_condition_value',
72
- id: $( this ).attr( 'data-id' ),
73
- group: $( this ).attr( 'data-group' ),
74
- condition: $( this ).val(),
75
- nonce: wpc.nonce
76
- };
77
- var condition_group = $( this ).parents( '.wpc-conditions' ).find( '.wpc-condition-group-' + data.group );
78
- var replace = '.wpc-value-wrap-' + data.id;
79
-
80
- // Loading icon
81
- condition_group.find( replace ).html( loading_wrap ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } });
82
-
83
- // Replace value field
84
- $.post( ajaxurl, data, function( response ) {
85
- condition_group.find( replace ).replaceWith( response );
86
- $( document.body ).trigger( 'wc-enhanced-select-init' );
87
- });
88
-
89
- // Update condition description
90
- var description = {
91
- action: wpc.action_prefix + 'update_condition_description',
92
- condition: data.condition,
93
- nonce: wpc.nonce
94
- };
95
-
96
- $.post( ajaxurl, description, function( description_response ) {
97
- condition_group.find( replace + ' ~ .wpc-description' ).replaceWith( description_response );
98
- // Tooltip
99
- $( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 200 });
100
- })
101
-
102
- });
103
-
104
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/woocommerce-advanced-free-shipping.min.js DELETED
@@ -1 +0,0 @@
1
- jQuery(function($){$(document.body).on("click",".wpc-condition-add",function(){var n=$(this),o={action:wpc.action_prefix+"add_condition",group:$(this).attr("data-group"),nonce:wpc.nonce},i=n.parents(".wpc-conditions").find(".wpc-condition-group-"+o.group),t='<div class="wpc-condition-wrap loading"></div>';i.append(t).children(":last").block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,o,function(n){i.find(" .wpc-condition-wrap.loading").first().replaceWith(function(){return $(n).hide().fadeIn("normal")})})}),$(document.body).on("click",".wpc-condition-delete",function(){1==$(this).closest(".wpc-condition-group").children(".wpc-condition-wrap").length?$(this).closest(".wpc-condition-group").fadeOut("normal",function(){$(this).next(".or-text").remove(),$(this).remove()}):$(this).closest(".wpc-condition-wrap").slideUp("fast",function(){$(this).remove()})}),$(document.body).on("click",".wpc-condition-group-add",function(){var n='<div class="wpc-condition-group loading"></div>',o=$(this).prev(".wpc-conditions"),i={action:wpc.action_prefix+"add_condition_group",group:parseInt($(this).prev(".wpc-conditions").find(".wpc-condition-group").length),nonce:wpc.nonce};o.append(n).children(":last").block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,i,function(n){o.find(".wpc-condition-group.loading").first().replaceWith(function(){return $(n).hide().fadeIn("normal")})})}),$(document.body).on("change",".wpc-condition",function(){var n='<span style="width: 30%; border: 1px solid transparent; display: inline-block;">&nbsp;</span>',o={action:wpc.action_prefix+"update_condition_value",id:$(this).attr("data-id"),group:$(this).attr("data-group"),condition:$(this).val(),nonce:wpc.nonce},i=$(this).parents(".wpc-conditions").find(".wpc-condition-group-"+o.group),t=".wpc-value-wrap-"+o.id;i.find(t).html(n).block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,o,function(n){i.find(t).replaceWith(n),$(document.body).trigger("wc-enhanced-select-init")});var c={action:wpc.action_prefix+"update_condition_description",condition:o.condition,nonce:wpc.nonce};$.post(ajaxurl,c,function(n){i.find(t+" ~ .wpc-description").replaceWith(n),$(".tips, .help_tip, .woocommerce-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})})})});
 
codeoversight.yml CHANGED
@@ -1,6 +1,6 @@
1
  php:
2
  align_array_elements: space
3
- align_doc_tags: double_space
4
  align_variables: space
5
  closing_newline: add
6
  closing_php_tag: remove
@@ -26,14 +26,18 @@ php:
26
  type_cast_inner_whitespace: no_space
27
  use_quotes: single_quotes
28
  variable_array_index_whitespace: whitespace
29
- whitespace_after_control_structure: whitespace
30
  whitespace_after_doc_asterisk: single_space
31
  whitespace_after_else: space
32
  whitespace_after_function_open: newline
33
  whitespace_after_function: double_newline
34
  whitespace_before_control_structure_brace: space
 
35
  whitespace_before_doc_asterisk: space
36
  whitespace_before_else: space
37
  whitespace_before_function_brace: space
38
  whitespace_before_function_close: newline
39
  whitespace_before_function_parentheses: no_space
 
 
 
 
1
  php:
2
  align_array_elements: space
3
+ align_doc_tags: space
4
  align_variables: space
5
  closing_newline: add
6
  closing_php_tag: remove
26
  type_cast_inner_whitespace: no_space
27
  use_quotes: single_quotes
28
  variable_array_index_whitespace: whitespace
 
29
  whitespace_after_doc_asterisk: single_space
30
  whitespace_after_else: space
31
  whitespace_after_function_open: newline
32
  whitespace_after_function: double_newline
33
  whitespace_before_control_structure_brace: space
34
+ whitespace_before_control_structure_parentheses: whitespace
35
  whitespace_before_doc_asterisk: space
36
  whitespace_before_else: space
37
  whitespace_before_function_brace: space
38
  whitespace_before_function_close: newline
39
  whitespace_before_function_parentheses: no_space
40
+
41
+ blacklist:
42
+ directories:
43
+ - libraries
includes/admin/admin-functions.php DELETED
@@ -1,100 +0,0 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
-
4
- if ( ! function_exists( 'wpc_html_field' ) ) {
5
-
6
- /**
7
- * Output html field.
8
- *
9
- * Output a new HTML field.
10
- *
11
- * @since 1.1.6
12
- *
13
- * @param array $args
14
- */
15
- function wpc_html_field( $args = array() ) {
16
-
17
- $args = wp_parse_args( $args, array(
18
- 'id' => '',
19
- 'type' => 'text',
20
- 'name' => '',
21
- 'class' => '',
22
- 'value' => null,
23
- 'default' => '',
24
- 'placeholder' => '',
25
- 'custom_attributes' => isset( $args['custom_attr'] ) ? $args['custom_attr'] : array(), // BC
26
- ) );
27
-
28
- $type = ! empty( $args['field'] ) ? $args['field'] : $args['type'];
29
- $class = is_array( $args['class'] ) ? implode( ' ', array_map( 'sanitize_html_class', $args['class'] ) ) : sanitize_html_class( $args['class'] );
30
- $value = isset( $args['value'] ) ? $args['value'] : '';
31
- $name = isset( $args['name'] ) ? $args['name'] : $args['id'];
32
- $custom_attributes = array();
33
- if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) {
34
- foreach ( $args['custom_attributes'] as $k => $v ) {
35
- $custom_attributes[ $k ] = esc_attr( $k ) . '="' . esc_attr( $v ) . '"';
36
- }
37
- }
38
-
39
- switch ( $type ) :
40
-
41
- case 'text' :
42
- case 'number' :
43
- ?><input
44
- name="<?php echo esc_attr( $name ); ?>"
45
- type="<?php echo $args['type']; ?>"
46
- id="<?php echo esc_attr( $args['id'] ); ?>"
47
- value="<?php echo esc_attr( $value ); ?>"
48
- class="input-text <?php echo $class; ?>"
49
- <?php echo implode( ' ', $custom_attributes ); ?>
50
- placeholder='<?php echo esc_attr( $args['placeholder'] ); ?>'
51
- ><?php
52
- break;
53
-
54
- case 'dropdown' :
55
- case 'select' :
56
-
57
- $options = is_array( $args['options'] ) ? $args['options'] : array();
58
-
59
- ?><select
60
- name="<?php echo esc_attr( $args['name'] ); ?>"
61
- id="<?php echo esc_attr( $args['id'] ); ?>"
62
- class="input-select <?php echo $class; ?>"
63
- <?php echo implode( ' ', $custom_attributes ); ?>
64
- ><?php
65
-
66
- foreach ( $options as $index => $values ) :
67
-
68
- if ( ! is_array( $values ) ) :
69
- ?><option value='<?php echo esc_attr( $index ); ?>' <?php selected( $index, $value ); ?>><?php echo esc_attr( $values ); ?></option><?php
70
- else :
71
- ?><optgroup label='<?php echo esc_attr( $index ); ?>'><?php
72
- foreach ( $values as $k => $v ) :
73
- ?><option value='<?php echo esc_attr( $k ); ?>' <?php selected( $k, $value ); ?>><?php echo esc_attr( $v ); ?></option><?php
74
- endforeach;
75
- ?></optgroup><?php
76
- endif;
77
-
78
- endforeach;
79
-
80
- if ( empty( $options ) ) :
81
- ?><option readonly disabled><?php
82
- _e( 'There are no options available', 'woocommerce-advanced-fees' );
83
- ?></option><?php
84
- endif;
85
-
86
- ?></select><?php
87
- break;
88
-
89
- default :
90
- case 'hook' :
91
-
92
- do_action( 'woocommerce_advanced_fees_condition_value_field_type_' . $args['type'], $args );
93
- break;
94
-
95
- endswitch;
96
-
97
- }
98
-
99
-
100
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/admin/class-wafs-admin.php CHANGED
@@ -18,12 +18,7 @@ class WAFS_Admin {
18
  *
19
  * @since 1.0.8
20
  */
21
- public function __construct() {
22
-
23
- // Initialize plugin parts
24
- add_action( 'admin_init', array( $this, 'init' ) );
25
-
26
- }
27
 
28
 
29
  /**
@@ -44,7 +39,6 @@ class WAFS_Admin {
44
 
45
  global $pagenow;
46
  if ( 'plugins.php' == $pagenow ) :
47
- // Plugins page
48
  add_filter( 'plugin_action_links_' . plugin_basename( WAFS()->file ), array( $this, 'add_plugin_action_links' ), 10, 2 );
49
  endif;
50
 
@@ -64,10 +58,8 @@ class WAFS_Admin {
64
 
65
  wp_register_style( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/css/woocommerce-advanced-free-shipping.min.css', WAFS()->file ), array(), WAFS()->version );
66
  wp_register_script( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/js/woocommerce-advanced-free-shipping' . $suffix . '.js', WAFS()->file ), array( 'jquery' ), WAFS()->version, true );
67
- wp_localize_script( 'woocommerce-advanced-free-shipping', 'wpc', array(
68
- 'nonce' => wp_create_nonce( 'wpc-ajax-nonce' ),
69
- 'action_prefix' => 'wafs_',
70
- 'asset_url' => plugins_url( 'assets/', WAFS()->file ),
71
  ) );
72
 
73
  if (
@@ -76,8 +68,14 @@ class WAFS_Admin {
76
  ( isset( $_REQUEST['section'] ) && 'advanced_free_shipping' == $_REQUEST['section'] )
77
  ) :
78
 
 
 
 
 
79
  wp_enqueue_style( 'woocommerce-advanced-free-shipping' );
80
  wp_enqueue_script( 'woocommerce-advanced-free-shipping' );
 
 
81
  wp_dequeue_script( 'autosave' );
82
 
83
  endif;
18
  *
19
  * @since 1.0.8
20
  */
21
+ public function __construct() {}
 
 
 
 
 
22
 
23
 
24
  /**
39
 
40
  global $pagenow;
41
  if ( 'plugins.php' == $pagenow ) :
 
42
  add_filter( 'plugin_action_links_' . plugin_basename( WAFS()->file ), array( $this, 'add_plugin_action_links' ), 10, 2 );
43
  endif;
44
 
58
 
59
  wp_register_style( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/css/woocommerce-advanced-free-shipping.min.css', WAFS()->file ), array(), WAFS()->version );
60
  wp_register_script( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/js/woocommerce-advanced-free-shipping' . $suffix . '.js', WAFS()->file ), array( 'jquery' ), WAFS()->version, true );
61
+ wp_localize_script( 'woocommerce-advanced-free-shipping', 'wafs', array(
62
+ 'nonce' => wp_create_nonce( 'wpc-ajax-nonce' ),
 
 
63
  ) );
64
 
65
  if (
68
  ( isset( $_REQUEST['section'] ) && 'advanced_free_shipping' == $_REQUEST['section'] )
69
  ) :
70
 
71
+ wp_localize_script( 'wp-conditions', 'wpc2', array(
72
+ 'action_prefix' => 'wafs_',
73
+ ) );
74
+
75
  wp_enqueue_style( 'woocommerce-advanced-free-shipping' );
76
  wp_enqueue_script( 'woocommerce-advanced-free-shipping' );
77
+ wp_enqueue_script( 'wp-conditions' );
78
+
79
  wp_dequeue_script( 'autosave' );
80
 
81
  endif;
includes/admin/class-wafs-condition.php CHANGED
@@ -58,7 +58,7 @@ class WAFS_Condition {
58
  *
59
  * @since 1.0.0
60
  */
61
- public function __construct( $id = null, $group = 0, $condition = null, $operator = null, $value = null ) {
62
 
63
  $this->id = $id;
64
  $this->group = $group;
@@ -144,17 +144,8 @@ class WAFS_Condition {
144
  * @return array List of available operators.
145
  */
146
  public function get_operators() {
147
-
148
- $operators = array(
149
- '==' => __( 'Equal to', 'woocommerce-advanced-free-shipping' ),
150
- '!=' => __( 'Not equal to', 'woocommerce-advanced-free-shipping' ),
151
- '>=' => __( 'Greater or equal to', 'woocommerce-advanced-free-shipping' ),
152
- '<=' => __( 'Less or equal to ', 'woocommerce-advanced-free-shipping' ),
153
- );
154
- $operators = apply_filters( 'wafs_operators', $operators );
155
-
156
- return $operators;
157
-
158
  }
159
 
160
 
@@ -171,150 +162,27 @@ class WAFS_Condition {
171
  public function get_value_field_args() {
172
 
173
  // Defaults
174
- $values = array(
175
  'name' => 'conditions[' . absint( $this->group ) . '][' . absint( $this->id ) . '][value]',
176
  'placeholder' => '',
177
  'type' => 'text',
178
- 'class' => array( 'wpc-value' )
179
  );
180
 
 
 
 
 
181
 
 
 
 
 
182
 
183
- switch ( $this->condition ) :
184
-
185
- default:
186
- case 'subtotal' :
187
- case 'subtotal_ex_tax' :
188
- case 'tax' :
189
- case 'quantity' :
190
- case 'coupon' :
191
- case 'weight' :
192
- $values['type'] = 'text';
193
- break;
194
-
195
- case 'contains_product' :
196
-
197
- $product = wc_get_product( $this->value );
198
- if ( $product ) {
199
- $values['custom_attributes']['data-selected'] = $product->get_formatted_name();
200
- }
201
-
202
- $values['type'] = 'text';
203
- $values['placeholder'] = __( 'Search for a product', 'woocommerce-advanced-messages' );
204
- $values['class'][] = 'wc-product-search';
205
-
206
- break;
207
-
208
- case 'contains_shipping_class' :
209
-
210
- $values['type'] = 'select';
211
- $values['options'][''] = __( 'No shipping class', 'woocommerce' );
212
-
213
- // Get all shipping classes
214
- foreach ( get_terms( 'product_shipping_class', array( 'hide_empty' => false ) ) as $shipping_class ) :
215
- $values['options'][ $shipping_class->slug ] = $shipping_class->name;
216
- endforeach;
217
-
218
- break;
219
-
220
- /**
221
- * User details
222
- */
223
-
224
- case 'zipcode' :
225
- case 'city' :
226
- $values['type'] = 'text';
227
- break;
228
-
229
- case 'state' :
230
-
231
- $values['type'] = 'select';
232
- $values['class'][] = 'wc-enhanced-select';
233
-
234
- $country_states = array();
235
- foreach ( WC()->countries->states as $country => $states ) :
236
-
237
- if ( empty( $states ) ) continue; // Don't show country if it has no states
238
- if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries
239
-
240
- foreach ( $states as $state_key => $state ) :
241
- $country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state;
242
- endforeach;
243
-
244
- $values['options'] = $country_states;
245
-
246
- endforeach;
247
-
248
- break;
249
-
250
- case 'country' :
251
-
252
- $values['field'] = 'select';
253
- $values['class'][] = 'wc-enhanced-select';
254
-
255
- $countries = WC()->countries->get_allowed_countries() + WC()->countries->get_shipping_countries();
256
- $continents = array();
257
- if ( method_exists( WC()->countries, 'get_continents' ) ) :
258
- foreach ( WC()->countries->get_continents() as $k => $v ) :
259
- $continents[ 'CO_' . $k ] = $v['name']; // Add prefix for country key compatibility
260
- endforeach;
261
- endif;
262
-
263
- if ( $continents ) {
264
- $values['options'][ __( 'Continents', 'woocommerce' ) ] = $continents;
265
- }
266
- $values['options'][ __( 'Countries', 'woocommerce' ) ] = $countries;
267
-
268
- break;
269
-
270
- case 'role' :
271
- $values['type'] = 'select';
272
- $roles = array_keys( get_editable_roles() );
273
- $values['options'] = array_combine( $roles, $roles );
274
- break;
275
-
276
- /**
277
- * Product
278
- */
279
-
280
- case 'width' :
281
- case 'height' :
282
- case 'length' :
283
- case 'stock' :
284
- $values['type'] = 'text';
285
- break;
286
-
287
- case 'stock_status' :
288
-
289
- $values['type'] = 'select';
290
- $values['options'] = array(
291
- 'instock' => __( 'In stock', 'woocommerce-advanced-free-shipping' ),
292
- 'outofstock' => __( 'Out of stock', 'woocommerce-advanced-free-shipping' ),
293
- );
294
-
295
- break;
296
-
297
- case 'category' :
298
-
299
- $values['type'] = 'select';
300
- $values['class'][] = 'wc-enhanced-select';
301
-
302
- $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
303
- foreach ( $categories as $category ) :
304
- $values['options'][ $category->slug ] = $category->name;
305
- endforeach;
306
-
307
- break;
308
-
309
-
310
- endswitch;
311
-
312
- $values = apply_filters( 'wafs_values', $values, $this->condition );
313
-
314
-
315
- $values = apply_filters( 'woocommerce_advanced_free_shipping_values', $values, $this->condition );
316
 
317
- return $values;
318
 
319
  }
320
 
@@ -327,23 +195,8 @@ class WAFS_Condition {
327
  * @since 1.0.0
328
  */
329
  public function get_description() {
330
-
331
- $descriptions = array(
332
- 'state' => __( 'States must be installed in WC.', 'woocommerce-advanced-free-shipping' ),
333
- 'weight' => __( 'Weight calculated on all the cart contents', 'woocommerce-advanced-free-shipping' ),
334
- 'length' => __( 'Compared to lengthiest product in cart', 'woocommerce-advanced-free-shipping' ),
335
- 'width' => __( 'Compared to widest product in cart', 'woocommerce-advanced-free-shipping' ),
336
- 'height' => __( 'Compared to highest product in cart', 'woocommerce-advanced-free-shipping' ),
337
- 'stock_status' => __( 'All products in cart must match stock status', 'woocommerce-advanced-free-shipping' ),
338
- 'category' => __( 'All products in cart must match category', 'woocommerce-advanced-free-shipping' ),
339
- 'contains_product' => __( 'Cart must contain one of this product', 'woocommerce-advanced-free-shipping' ),
340
- 'contains_shipping_class' => __( 'Cart must contain at least one product with the selected shipping class', 'woocommerce-advanced-free-shipping' ),
341
- );
342
-
343
- $descriptions = apply_filters( 'wafs_descriptions', $descriptions );
344
-
345
  return isset( $descriptions[ $this->condition ] ) ? $descriptions[ $this->condition ] : '';
346
-
347
  }
348
 
349
 
58
  *
59
  * @since 1.0.0
60
  */
61
+ public function __construct( $id = null, $group = 0, $condition = 'subtotal', $operator = null, $value = null ) {
62
 
63
  $this->id = $id;
64
  $this->group = $group;
144
  * @return array List of available operators.
145
  */
146
  public function get_operators() {
147
+ $wpc_condition = wpc_get_condition( $this->condition );
148
+ return apply_filters( 'woocommerce_Advanced_Shipping_Validation_operators', $wpc_condition->get_available_operators() );
 
 
 
 
 
 
 
 
 
149
  }
150
 
151
 
162
  public function get_value_field_args() {
163
 
164
  // Defaults
165
+ $default_field_args = array(
166
  'name' => 'conditions[' . absint( $this->group ) . '][' . absint( $this->id ) . '][value]',
167
  'placeholder' => '',
168
  'type' => 'text',
169
+ 'class' => array( 'wpc-value' ),
170
  );
171
 
172
+ $field_args = $default_field_args;
173
+ if ( $condition = wpc_get_condition( $this->condition ) ) {
174
+ $field_args = wp_parse_args( $condition->get_value_field_args(), $field_args );
175
+ }
176
 
177
+ if ( $this->condition == 'contains_product' && $product = wc_get_product( $this->value ) ) {
178
+ $field_args['custom_attributes']['data-selected'] = $product->get_formatted_name(); // WC < 2.7
179
+ $field_args['options'][ $this->value ] = $product->get_formatted_name(); // WC >= 2.7
180
+ }
181
 
182
+ $field_args = apply_filters( 'wafs_values', $field_args, $this->condition );
183
+ $field_args = apply_filters( 'woocommerce_advanced_free_shipping_values', $field_args, $this->condition );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
+ return $field_args;
186
 
187
  }
188
 
195
  * @since 1.0.0
196
  */
197
  public function get_description() {
198
+ $descriptions = apply_filters( 'wafs_descriptions', wpc_condition_descriptions() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  return isset( $descriptions[ $this->condition ] ) ? $descriptions[ $this->condition ] : '';
 
200
  }
201
 
202
 
includes/admin/views/conditions-table.php CHANGED
@@ -19,7 +19,7 @@ $shipping_rates = wafs_get_rates( array( 'post_status' => array( 'draft', 'publi
19
  </th>
20
  <td class="forminp" id="<?php echo $this->id; ?>_shipping_methods">
21
 
22
- <table class='wp-list-table wpc-conditions-post-table widefat'>
23
  <thead>
24
  <tr>
25
  <th style='padding-left: 10px;'><?php _e( 'Title', 'woocommerce-advanced-free-shipping' ); ?></th>
19
  </th>
20
  <td class="forminp" id="<?php echo $this->id; ?>_shipping_methods">
21
 
22
+ <table class='wp-list-table wpc-conditions-post-table wpc-sortable-post-table widefat'>
23
  <thead>
24
  <tr>
25
  <th style='padding-left: 10px;'><?php _e( 'Title', 'woocommerce-advanced-free-shipping' ); ?></th>
includes/admin/views/html-condition-group.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ ?><div class='wpc-condition-group-wrap'>
5
+ <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p>
6
+
7
+ <div class='wpc-condition-group clearfix' data-group='<?php echo absint( $condition_group ); ?>'>
8
+
9
+ <span class='wpc-condition-group-actions alignright'>
10
+ <a href='javascript:void(0);' class='duplicate'><?php _e( 'Duplicate', 'woocommerce-advanced-free-shipping' ); ?></a>&nbsp;|&nbsp;<a href='javascript:void(0);' class='delete'><?php _e( 'Delete', 'woocommerce-advanced-free-shipping' ); ?></a>
11
+ </span>
12
+ <p class='match-text'><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p>
13
+
14
+ <div class='wpc-conditions-list'><?php
15
+
16
+ if ( ! empty( $conditions ) ) :
17
+
18
+ foreach ( $conditions as $condition_id => $condition ) :
19
+ $wp_condition = new WAFS_Condition( $condition_id, $condition_group, $condition['condition'], $condition['operator'], $condition['value'] );
20
+ $wp_condition->output_condition_row();
21
+ endforeach;
22
+
23
+ else :
24
+
25
+ $wp_condition = new WAFS_Condition( null, $condition_group );
26
+ $wp_condition->output_condition_row();
27
+
28
+ endif;
29
+
30
+ ?></div>
31
+
32
+ <div class="wpc-condition-template hidden" style="display: none;"><?php
33
+ $wp_condition = new WAFS_Condition( '9999', $condition_group );
34
+ $wp_condition->output_condition_row();
35
+ ?></div>
36
+ <a style="margin-top: 0.5em; margin-right: 63px;" class='wpc-condition-add wpc-add button alignright' data-group='<?php echo absint( $condition_group ); ?>' href='javascript:void(0);'><?php _e( 'Add condition', 'woocommerce-advanced-free-shipping' ); ?></a>
37
+
38
+ </div>
39
+ </div>
includes/admin/views/html-condition-row.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
 
 
 
4
  ?><div class='wpc-condition-wrap'>
5
 
6
  <!-- Condition -->
7
- <span class='wpc-condition-wrap wpc-condition-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php
8
 
9
  $condition_field_args = array(
10
  'type' => 'select',
@@ -13,8 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13
  'options' => $wp_condition->get_conditions(),
14
  'value' => $wp_condition->condition,
15
  'custom_attr' => array(
16
- 'data-group' => absint( $wp_condition->group ),
17
- 'data-id' => absint( $wp_condition->id ),
18
  ),
19
  );
20
  wpc_html_field( $condition_field_args );
@@ -23,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
23
 
24
 
25
  <!-- Operator -->
26
- <span class='wpc-operator-wrap wpc-operator-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php
27
 
28
  $operator_field_args = array(
29
  'type' => 'select',
@@ -38,24 +39,23 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
38
 
39
 
40
  <!-- Value -->
41
- <span class='wpc-value-wrap wpc-value-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php
42
  $value_field_args = wp_parse_args( array( 'value' => $wp_condition->value ), $wp_condition->get_value_field_args() );
43
  wpc_html_field( $value_field_args );
44
  ?></span>
45
 
46
 
47
- <!-- Add / Delete-->
48
- <a class='button wpc-condition-add' data-group='<?php echo absint( $this->group ); ?>' href='javascript:void(0);'>+</a>&nbsp;
49
- <a class='button wpc-condition-delete' href='javascript:void(0);'>-</a><?php
50
 
51
 
52
  // Description
53
  if ( $desc = $wp_condition->get_description() ) :
54
- ?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'>
55
- <img class='help_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' data-tip="<?php echo esc_html( $desc ); ?>" />
56
  </span><?php
57
  else :
58
- ?><span class='wpc-description wpc-no-description <?php echo $wp_condition->condition; ?>-description'><?php
59
  endif;
60
 
61
  ?></div>
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
 
4
+ $condition = wpc_get_condition( $wp_condition->condition );
5
+
6
  ?><div class='wpc-condition-wrap'>
7
 
8
  <!-- Condition -->
9
+ <span class='wpc-condition-field-wrap'><?php
10
 
11
  $condition_field_args = array(
12
  'type' => 'select',
15
  'options' => $wp_condition->get_conditions(),
16
  'value' => $wp_condition->condition,
17
  'custom_attr' => array(
18
+ 'data-id' => absint( $wp_condition->id ),
 
19
  ),
20
  );
21
  wpc_html_field( $condition_field_args );
24
 
25
 
26
  <!-- Operator -->
27
+ <span class='wpc-operator-field-wrap'><?php
28
 
29
  $operator_field_args = array(
30
  'type' => 'select',
39
 
40
 
41
  <!-- Value -->
42
+ <span class='wpc-value-field-wrap'><?php
43
  $value_field_args = wp_parse_args( array( 'value' => $wp_condition->value ), $wp_condition->get_value_field_args() );
44
  wpc_html_field( $value_field_args );
45
  ?></span>
46
 
47
 
48
+ <!-- Delete-->
49
+ <a class='button wpc-condition-delete' href='javascript:void(0);'></a><?php
 
50
 
51
 
52
  // Description
53
  if ( $desc = $wp_condition->get_description() ) :
54
+ ?><span class='wpc-description'>
55
+ <span class="woocommerce-help-tip" data-tip="<?php echo wp_kses_post( $desc ); ?>"></span>
56
  </span><?php
57
  else :
58
+ ?><span class='wpc-description wpc-no-description'><?php
59
  endif;
60
 
61
  ?></div>
includes/admin/views/meta-box-conditions.php CHANGED
@@ -7,37 +7,27 @@ $condition_groups = get_post_meta( $post->ID, '_wafs_shipping_method_conditions'
7
  ?><div class='wpc-conditions wpc-conditions-meta-box'>
8
 
9
  <p>
10
- <strong><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong>
11
  </p><?php
12
 
13
  if ( ! empty( $condition_groups ) ) :
14
 
15
  foreach ( $condition_groups as $condition_group => $conditions ) :
16
-
17
- ?><div class='wpc-condition-group wpc-condition-group-<?php echo absint( $condition_group ); ?>' data-group='<?php echo absint( $condition_group ); ?>'>
18
-
19
- <p class='or-text'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p><?php
20
-
21
- foreach ( $conditions as $condition_id => $condition ) :
22
- $wp_condition = new WAFS_Condition( $condition_id, $condition_group, $condition['condition'], $condition['operator'], $condition['value'] );
23
- $wp_condition->output_condition_row();
24
- endforeach;
25
-
26
- ?></div>
27
-
28
- <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
29
-
30
  endforeach;
31
 
32
  else :
33
 
34
- ?><div class='wpc-condition-group wpc-condition-group-0' data-group='0'><?php
35
- $wp_condition = new WAFS_Condition();
36
- $wp_condition->output_condition_row();
37
- ?></div><?php
38
 
39
  endif;
40
 
41
- ?></div>
42
 
 
 
 
 
 
43
  <a class='button wpc-condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'woocommerce-advanced-free-shipping' ); ?></a>
7
  ?><div class='wpc-conditions wpc-conditions-meta-box'>
8
 
9
  <p>
10
+ <strong><?php _e( 'Match one of the condition groups to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong>
11
  </p><?php
12
 
13
  if ( ! empty( $condition_groups ) ) :
14
 
15
  foreach ( $condition_groups as $condition_group => $conditions ) :
16
+ include plugin_dir_path( __FILE__ ) . 'html-condition-group.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  endforeach;
18
 
19
  else :
20
 
21
+ $condition_group = '0';
22
+ include plugin_dir_path( __FILE__ ) . 'html-condition-group.php';
 
 
23
 
24
  endif;
25
 
26
+ ?></div>
27
 
28
+ <div class='wpc-condition-group-template hidden' style='display: none'><?php
29
+ $condition_group = '9999';
30
+ $conditions = array();
31
+ include plugin_dir_path( __FILE__ ) . 'html-condition-group.php';
32
+ ?></div>
33
  <a class='button wpc-condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'woocommerce-advanced-free-shipping' ); ?></a>
includes/admin/views/meta-box-settings.php CHANGED
@@ -32,5 +32,4 @@ $settings['shipping_title'] = ! empty( $settings['shipping_title'] ) ? $settings
32
 
33
  </p>
34
 
35
-
36
  </div>
32
 
33
  </p>
34
 
 
35
  </div>
includes/class-wafs-ajax.php CHANGED
@@ -19,60 +19,8 @@ class WAFS_Ajax {
19
  */
20
  public function __construct() {
21
 
22
- // Add elements
23
- add_action( 'wp_ajax_wafs_add_condition', array( $this, 'add_condition' ) );
24
- add_action( 'wp_ajax_wafs_add_condition_group', array( $this, 'add_condition_group' ) );
25
-
26
  // Update elements
27
  add_action( 'wp_ajax_wafs_update_condition_value', array( $this, 'update_condition_value' ) );
28
- add_action( 'wp_ajax_wafs_update_condition_description', array( $this, 'update_condition_description' ) );
29
-
30
- }
31
-
32
-
33
- /**
34
- * Add condition.
35
- *
36
- * Output the HTML of a new condition row.
37
- *
38
- * @since 1.0.0
39
- */
40
- public function add_condition() {
41
-
42
- check_ajax_referer( 'wpc-ajax-nonce', 'nonce' );
43
-
44
- $wp_condition = new WAFS_Condition( null, $_POST['group'] );
45
- $wp_condition->output_condition_row();
46
-
47
- die();
48
-
49
- }
50
-
51
-
52
- /**
53
- * Condition group.
54
- *
55
- * Output the HTML of a new condition group.
56
- *
57
- * @since 1.0.0
58
- */
59
- public function add_condition_group() {
60
-
61
- check_ajax_referer( 'wpc-ajax-nonce', 'nonce' );
62
- $group = absint( $_POST['group'] );
63
-
64
- ?><div class='wpc-condition-group wpc-condition-group-<?php echo $group; ?>' data-group='<?php echo $group; ?>'>
65
-
66
- <p class='or-match'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p><?php
67
-
68
- $wp_condition = new WAFS_Condition( null, $group );
69
- $wp_condition->output_condition_row();
70
-
71
- ?></div>
72
-
73
- <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
74
-
75
- die();
76
 
77
  }
78
 
@@ -91,7 +39,7 @@ class WAFS_Ajax {
91
  $wp_condition = new WAFS_Condition( $_POST['id'], $_POST['group'], $_POST['condition'] );
92
  $value_field_args = $wp_condition->get_value_field_args();
93
 
94
- ?><span class='wpc-value-wrap wpc-value-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php
95
  wpc_html_field( $value_field_args );
96
  ?></span><?php
97
 
@@ -100,32 +48,4 @@ class WAFS_Ajax {
100
  }
101
 
102
 
103
- /**
104
- * Update description.
105
- *
106
- * Render the corresponding description for the condition key.
107
- *
108
- * @since 1.0.0
109
- */
110
- public function update_condition_description() {
111
-
112
- check_ajax_referer( 'wpc-ajax-nonce', 'nonce' );
113
-
114
- $condition = sanitize_text_field( $_POST['condition'] );
115
- $wp_condition = new WAFS_Condition( null, null, $condition );
116
-
117
- if ( $desc = $wp_condition->get_description() ) {
118
- ?><span class='wpc-description wpc-no-description <?php echo $desc; ?>-description'><?php
119
- die();
120
- }
121
-
122
- ?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'>
123
- <img class='help_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' data-tip="<?php echo esc_html( $wp_condition->get_description() ); ?>" />
124
- </span><?php
125
-
126
- die();
127
-
128
- }
129
-
130
-
131
  }
19
  */
20
  public function __construct() {
21
 
 
 
 
 
22
  // Update elements
23
  add_action( 'wp_ajax_wafs_update_condition_value', array( $this, 'update_condition_value' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  }
26
 
39
  $wp_condition = new WAFS_Condition( $_POST['id'], $_POST['group'], $_POST['condition'] );
40
  $value_field_args = $wp_condition->get_value_field_args();
41
 
42
+ ?><span class='wpc-value-field-wrap'><?php
43
  wpc_html_field( $value_field_args );
44
  ?></span><?php
45
 
48
  }
49
 
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
includes/class-wafs-match-conditions.php CHANGED
@@ -19,339 +19,10 @@ class WAFS_Match_Conditions {
19
  * @since 1.0.0
20
  */
21
  public function __construct() {
22
-
23
- add_filter( 'wafs_match_condition_subtotal', array( $this, 'wafs_match_condition_subtotal' ), 10, 3 );
24
- add_filter( 'wafs_match_condition_subtotal_ex_tax', array( $this, 'wafs_match_condition_subtotal_ex_tax' ), 10, 3 );
25
- add_filter( 'wafs_match_condition_tax', array( $this, 'wafs_match_condition_tax' ), 10, 3 );
26
- add_filter( 'wafs_match_condition_quantity', array( $this, 'wafs_match_condition_quantity' ), 10, 3 );
27
- add_filter( 'wafs_match_condition_contains_product', array( $this, 'wafs_match_condition_contains_product' ), 10, 3 );
28
- add_filter( 'wafs_match_condition_coupon', array( $this, 'wafs_match_condition_coupon' ), 10, 3 );
29
- add_filter( 'wafs_match_condition_weight', array( $this, 'wafs_match_condition_weight' ), 10, 3 );
30
- add_filter( 'wafs_match_condition_contains_shipping_class', array( $this, 'wafs_match_condition_contains_shipping_class' ), 10, 3 );
31
-
32
  add_filter( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 );
33
- add_filter( 'wafs_match_condition_city', array( $this, 'wafs_match_condition_city' ), 10, 3 );
34
- add_filter( 'wafs_match_condition_state', array( $this, 'wafs_match_condition_state' ), 10, 3 );
35
- add_filter( 'wafs_match_condition_country', array( $this, 'wafs_match_condition_country' ), 10, 3 );
36
- add_filter( 'wafs_match_condition_role', array( $this, 'wafs_match_condition_role' ), 10, 3 );
37
-
38
- add_filter( 'wafs_match_condition_width', array( $this, 'wafs_match_condition_width' ), 10, 3 );
39
- add_filter( 'wafs_match_condition_height', array( $this, 'wafs_match_condition_height' ), 10, 3 );
40
- add_filter( 'wafs_match_condition_length', array( $this, 'wafs_match_condition_length' ), 10, 3 );
41
- add_filter( 'wafs_match_condition_stock', array( $this, 'wafs_match_condition_stock' ), 10, 3 );
42
- add_filter( 'wafs_match_condition_stock_status', array( $this, 'wafs_match_condition_stock_status' ), 10, 3 );
43
- add_filter( 'wafs_match_condition_category', array( $this, 'wafs_match_condition_category' ), 10, 3 );
44
-
45
- }
46
-
47
-
48
- /**
49
- * Subtotal.
50
- *
51
- * Match the condition value against the cart subtotal.
52
- *
53
- * @since 1.0.0
54
- *
55
- * @param bool $match Current match value.
56
- * @param string $operator Operator selected by the user in the condition row.
57
- * @param mixed $value Value given by the user in the condition row.
58
- * @return bool Matching result, true if results match, otherwise false.
59
- */
60
- public function wafs_match_condition_subtotal( $match, $operator, $value ) {
61
-
62
- if ( ! isset( WC()->cart ) ) return $match;
63
-
64
- if ( '==' == $operator ) :
65
- $match = ( WC()->cart->subtotal == $value );
66
- elseif ( '!=' == $operator ) :
67
- $match = ( WC()->cart->subtotal != $value );
68
- elseif ( '>=' == $operator ) :
69
- $match = ( WC()->cart->subtotal >= $value );
70
- elseif ( '<=' == $operator ) :
71
- $match = ( WC()->cart->subtotal <= $value );
72
- endif;
73
-
74
- return $match;
75
-
76
- }
77
-
78
-
79
- /**
80
- * Subtotal excl. taxes.
81
- *
82
- * Match the condition value against the cart subtotal excl. taxes.
83
- *
84
- * @since 1.0.0
85
- *
86
- * @param bool $match Current match value.
87
- * @param string $operator Operator selected by the user in the condition row.
88
- * @param mixed $value Value given by the user in the condition row.
89
- * @return bool Matching result, true if results match, otherwise false.
90
- */
91
- public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
92
-
93
- if ( ! isset( WC()->cart ) ) return $match;
94
-
95
- if ( '==' == $operator ) :
96
- $match = ( WC()->cart->subtotal_ex_tax == $value );
97
- elseif ( '!=' == $operator ) :
98
- $match = ( WC()->cart->subtotal_ex_tax != $value );
99
- elseif ( '>=' == $operator ) :
100
- $match = ( WC()->cart->subtotal_ex_tax >= $value );
101
- elseif ( '<=' == $operator ) :
102
- $match = ( WC()->cart->subtotal_ex_tax <= $value );
103
- endif;
104
-
105
- return $match;
106
-
107
- }
108
-
109
-
110
- /**
111
- * Taxes.
112
- *
113
- * Match the condition value against the cart taxes.
114
- *
115
- * @since 1.0.0
116
- *
117
- * @param bool $match Current match value.
118
- * @param string $operator Operator selected by the user in the condition row.
119
- * @param mixed $value Value given by the user in the condition row.
120
- * @return bool Matching result, true if results match, otherwise false.
121
- */
122
- public function wafs_match_condition_tax( $match, $operator, $value ) {
123
-
124
- if ( ! isset( WC()->cart ) ) return $match;
125
-
126
- $taxes = array_sum( (array) WC()->cart->taxes );
127
-
128
- if ( '==' == $operator ) :
129
- $match = ( $taxes == $value );
130
- elseif ( '!=' == $operator ) :
131
- $match = ( $taxes != $value );
132
- elseif ( '>=' == $operator ) :
133
- $match = ( $taxes >= $value );
134
- elseif ( '<=' == $operator ) :
135
- $match = ( $taxes <= $value );
136
- endif;
137
-
138
- return $match;
139
-
140
- }
141
-
142
-
143
- /**
144
- * Quantity.
145
- *
146
- * Match the condition value against the cart quantity.
147
- * This also includes product quantities.
148
- *
149
- * @since 1.0.0
150
- *
151
- * @param bool $match Current match value.
152
- * @param string $operator Operator selected by the user in the condition row.
153
- * @param mixed $value Value given by the user in the condition row.
154
- * @return bool Matching result, true if results match, otherwise false.
155
- */
156
- public function wafs_match_condition_quantity( $match, $operator, $value ) {
157
-
158
- if ( ! isset( WC()->cart ) ) return $match;
159
-
160
- if ( '==' == $operator ) :
161
- $match = ( WC()->cart->cart_contents_count == $value );
162
- elseif ( '!=' == $operator ) :
163
- $match = ( WC()->cart->cart_contents_count != $value );
164
- elseif ( '>=' == $operator ) :
165
- $match = ( WC()->cart->cart_contents_count >= $value );
166
- elseif ( '<=' == $operator ) :
167
- $match = ( WC()->cart->cart_contents_count <= $value );
168
- endif;
169
-
170
- return $match;
171
-
172
- }
173
-
174
-
175
- /**
176
- * Contains product.
177
- *
178
- * Matches if the condition value product is in the cart.
179
- *
180
- * @since 1.0.0
181
- *
182
- * @param bool $match Current match value.
183
- * @param string $operator Operator selected by the user in the condition row.
184
- * @param mixed $value Value given by the user in the condition row.
185
- * @return bool Matching result, true if results match, otherwise false.
186
- */
187
- public function wafs_match_condition_contains_product( $match, $operator, $value ) {
188
-
189
- if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
190
-
191
- $product_ids = array();
192
- foreach ( WC()->cart->cart_contents as $product ) :
193
- $product_ids[] = $product['product_id'];
194
- endforeach;
195
-
196
- if ( '==' == $operator ) :
197
- $match = ( in_array( $value, $product_ids ) );
198
- elseif ( '!=' == $operator ) :
199
- $match = ( ! in_array( $value, $product_ids ) );
200
- endif;
201
-
202
- return $match;
203
-
204
- }
205
-
206
-
207
- /**
208
- * Coupon.
209
- *
210
- * Match the condition value against the applied coupons.
211
- *
212
- * @since 1.0.0
213
- *
214
- * @param bool $match Current match value.
215
- * @param string $operator Operator selected by the user in the condition row.
216
- * @param mixed $value Value given by the user in the condition row.
217
- * @return bool Matching result, true if results match, otherwise false.
218
- */
219
- public function wafs_match_condition_coupon( $match, $operator, $value ) {
220
-
221
- if ( ! isset( WC()->cart ) ) :
222
- return $match;
223
- endif;
224
-
225
- $coupons = array( 'percent' => array(), 'fixed' => array() );
226
- foreach ( WC()->cart->get_coupons() as $coupon ) {
227
- $type = str_replace( '_product', '', $coupon->discount_type );
228
- $type = str_replace( '_cart', '', $type );
229
- $coupons[ $type ][] = $coupon->coupon_amount;
230
- }
231
-
232
- // Match against coupon percentage
233
- if ( strpos( $value, '%' ) !== false ) {
234
-
235
- $percentage_value = str_replace( '%', '', $value );
236
- if ( '==' == $operator ) :
237
- $match = in_array( $percentage_value, $coupons['percent'] );
238
- elseif ( '!=' == $operator ) :
239
- $match = ! in_array( $percentage_value, $coupons['percent'] );
240
- elseif ( '>=' == $operator ) :
241
- $match = empty( $coupons['percent'] ) ? $match : ( min( $coupons['percent'] ) >= $percentage_value );
242
- elseif ( '<=' == $operator ) :
243
- $match = ! is_array( $coupons['percent'] ) ? false : ( max( $coupons['percent'] ) <= $percentage_value );
244
- endif;
245
-
246
- // Match against coupon amount
247
- } elseif( strpos( $value, '$' ) !== false ) {
248
-
249
- $amount_value = str_replace( '$', '', $value );
250
- if ( '==' == $operator ) :
251
- $match = in_array( $amount_value, $coupons['fixed'] );
252
- elseif ( '!=' == $operator ) :
253
- $match = ! in_array( $amount_value, $coupons['fixed'] );
254
- elseif ( '>=' == $operator ) :
255
- $match = empty( $coupons['fixed'] ) ? $match : ( min( $coupons['fixed'] ) >= $amount_value );
256
- elseif ( '<=' == $operator ) :
257
- $match = ! is_array( $coupons['fixed'] ) ? $match : ( max( $coupons['fixed'] ) <= $amount_value );
258
- endif;
259
-
260
- // Match coupon codes
261
- } else {
262
-
263
- if ( '==' == $operator ) :
264
- $match = ( in_array( $value, WC()->cart->applied_coupons ) );
265
- elseif ( '!=' == $operator ) :
266
- $match = ( ! in_array( $value, WC()->cart->applied_coupons ) );
267
- endif;
268
-
269
- }
270
-
271
- return $match;
272
-
273
- }
274
-
275
-
276
- /**
277
- * Weight.
278
- *
279
- * Match the condition value against the cart weight.
280
- *
281
- * @since 1.0.0
282
- *
283
- * @param bool $match Current match value.
284
- * @param string $operator Operator selected by the user in the condition row.
285
- * @param mixed $value Value given by the user in the condition row.
286
- * @return bool Matching result, true if results match, otherwise false.
287
- */
288
- public function wafs_match_condition_weight( $match, $operator, $value ) {
289
-
290
- if ( ! isset( WC()->cart ) ) return $match;
291
-
292
- if ( '==' == $operator ) :
293
- $match = ( WC()->cart->cart_contents_weight == $value );
294
- elseif ( '!=' == $operator ) :
295
- $match = ( WC()->cart->cart_contents_weight != $value );
296
- elseif ( '>=' == $operator ) :
297
- $match = ( WC()->cart->cart_contents_weight >= $value );
298
- elseif ( '<=' == $operator ) :
299
- $match = ( WC()->cart->cart_contents_weight <= $value );
300
- endif;
301
-
302
- return $match;
303
-
304
  }
305
 
306
 
307
- /**
308
- * Shipping class.
309
- *
310
- * Matches if the condition value shipping class is in the cart.
311
- *
312
- * @since 1.1.0
313
- *
314
- * @param bool $match Current match value.
315
- * @param string $operator Operator selected by the user in the condition row.
316
- * @param mixed $value Value given by the user in the condition row.
317
- * @return bool Matching result, true if results match, otherwise false.
318
- */
319
- public function wafs_match_condition_contains_shipping_class( $match, $operator, $value ) {
320
-
321
- if ( ! isset( WC()->cart ) ) return $match;
322
-
323
- // True until proven false
324
- if ( $operator == '!=' ) :
325
- $match = true;
326
- endif;
327
-
328
- foreach ( WC()->cart->cart_contents as $product ) :
329
-
330
- $id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
331
- $product = wc_get_product( $id );
332
-
333
- if ( $operator == '==' ) :
334
- if ( $product->get_shipping_class() == $value ) :
335
- return true;
336
- endif;
337
- elseif ( $operator == '!=' ) :
338
- if ( $product->get_shipping_class() == $value ) :
339
- return false;
340
- endif;
341
- endif;
342
-
343
- endforeach;
344
-
345
- return $match;
346
-
347
- }
348
-
349
-
350
- /******************************************************
351
- * User conditions
352
- *****************************************************/
353
-
354
-
355
  /**
356
  * Zipcode.
357
  *
@@ -450,409 +121,4 @@ class WAFS_Match_Conditions {
450
  }
451
 
452
 
453
- /**
454
- * City.
455
- *
456
- * Match the condition value against the users shipping city.
457
- *
458
- * @since 1.0.0
459
- *
460
- * @param bool $match Current match value.
461
- * @param string $operator Operator selected by the user in the condition row.
462
- * @param mixed $value Value given by the user in the condition row.
463
- * @return bool Matching result, true if results match, otherwise false.
464
- */
465
- public function wafs_match_condition_city( $match, $operator, $value ) {
466
-
467
- if ( ! isset( WC()->customer ) ) return $match;
468
-
469
- $customer_city = strtolower( WC()->customer->get_shipping_city() );
470
- $value = strtolower( $value );
471
-
472
- if ( '==' == $operator ) :
473
-
474
- if ( preg_match( '/\, ?/', $value ) ) :
475
- $match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
476
- else :
477
- $match = ( $value == $customer_city );
478
- endif;
479
-
480
- elseif ( '!=' == $operator ) :
481
-
482
- if ( preg_match( '/\, ?/', $value ) ) :
483
- $match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
484
- else :
485
- $match = ( $value == $customer_city );
486
- endif;
487
-
488
- endif;
489
-
490
- return $match;
491
-
492
- }
493
-
494
-
495
- /**
496
- * State.
497
- *
498
- * Match the condition value against the users shipping state
499
- *
500
- * @since 1.0.0
501
- *
502
- * @param bool $match Current match value.
503
- * @param string $operator Operator selected by the user in the condition row.
504
- * @param mixed $value Value given by the user in the condition row.
505
- * @return bool Matching result, true if results match, otherwise false.
506
- */
507
- public function wafs_match_condition_state( $match, $operator, $value ) {
508
-
509
- if ( ! isset( WC()->customer ) ) return $match;
510
-
511
- $state = WC()->customer->get_shipping_country() . '_' . WC()->customer->get_shipping_state();
512
-
513
- if ( '==' == $operator ) :
514
- $match = ( $state == $value );
515
- elseif ( '!=' == $operator ) :
516
- $match = ( $state != $value );
517
- endif;
518
-
519
- return $match;
520
-
521
- }
522
-
523
-
524
- /**
525
- * Country.
526
- *
527
- * Match the condition value against the users shipping country.
528
- *
529
- * @since 1.0.0
530
- *
531
- * @param bool $match Current match value.
532
- * @param string $operator Operator selected by the user in the condition row.
533
- * @param mixed $value Value given by the user in the condition row.
534
- * @return bool Matching result, true if results match, otherwise false.
535
- */
536
- public function wafs_match_condition_country( $match, $operator, $value ) {
537
-
538
- if ( ! isset( WC()->customer ) ) :
539
- return $match;
540
- endif;
541
-
542
- $user_country = WC()->customer->get_shipping_country();
543
-
544
- if ( method_exists( WC()->countries, 'get_continent_code_for_country' ) ) :
545
- $user_continent = WC()->countries->get_continent_code_for_country( $user_country );
546
- endif;
547
-
548
- if ( '==' == $operator ) :
549
- $match = stripos( $user_country, $value ) === 0;
550
-
551
- // Check for continents if available
552
- if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) :
553
- $match = stripos( $user_continent, str_replace( 'CO_','', $value ) ) === 0;
554
- endif;
555
- elseif ( '!=' == $operator ) :
556
- $match = stripos( $user_country, $value ) === false;
557
-
558
- // Check for continents if available
559
- if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) :
560
- $match = stripos( $user_continent, str_replace( 'CO_','', $value ) ) === false;
561
- endif;
562
- endif;
563
-
564
- return $match;
565
-
566
- }
567
-
568
-
569
- /**
570
- * User role.
571
- *
572
- * Match the condition value against the users role.
573
- *
574
- * @since 1.0.0
575
- * @global object $current_user Current user object for capabilities.
576
- *
577
- * @param bool $match Current match value.
578
- * @param string $operator Operator selected by the user in the condition row.
579
- * @param mixed $value Value given by the user in the condition row.
580
- * @return bool Matching result, true if results match, otherwise false.
581
- */
582
- public function wafs_match_condition_role( $match, $operator, $value ) {
583
-
584
- global $current_user;
585
-
586
- if ( '==' == $operator ) :
587
- $match = ( array_key_exists( $value, $current_user->caps ) );
588
- elseif ( '!=' == $operator ) :
589
- $match = ( ! array_key_exists( $value, $current_user->caps ) );
590
- endif;
591
-
592
- return $match;
593
-
594
- }
595
-
596
-
597
- /******************************************************
598
- * Product conditions
599
- *****************************************************/
600
-
601
-
602
- /**
603
- * Width.
604
- *
605
- * Match the condition value against the widest product in the cart.
606
- *
607
- * @since 1.0.0
608
- *
609
- * @param bool $match Current match value.
610
- * @param string $operator Operator selected by the user in the condition row.
611
- * @param mixed $value Value given by the user in the condition row.
612
- * @return bool Matching result, true if results match, otherwise false.
613
- */
614
- public function wafs_match_condition_width( $match, $operator, $value ) {
615
-
616
- if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
617
-
618
- foreach ( WC()->cart->cart_contents as $product ) :
619
-
620
- if ( true == $product['data']->variation_has_width ) :
621
- $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) );
622
- else :
623
- $width[] = ( get_post_meta( $product['product_id'], '_width', true ) );
624
- endif;
625
-
626
- endforeach;
627
-
628
- $max_width = max( (array) $width );
629
-
630
- if ( '==' == $operator ) :
631
- $match = ( $max_width == $value );
632
- elseif ( '!=' == $operator ) :
633
- $match = ( $max_width != $value );
634
- elseif ( '>=' == $operator ) :
635
- $match = ( $max_width >= $value );
636
- elseif ( '<=' == $operator ) :
637
- $match = ( $max_width <= $value );
638
- endif;
639
-
640
- return $match;
641
-
642
- }
643
-
644
-
645
- /**
646
- * Height.
647
- *
648
- * Match the condition value against the highest product in the cart.
649
- *
650
- * @since 1.0.0
651
- *
652
- * @param bool $match Current match value.
653
- * @param string $operator Operator selected by the user in the condition row.
654
- * @param mixed $value Value given by the user in the condition row.
655
- * @return bool Matching result, true if results match, otherwise false.
656
- */
657
- public function wafs_match_condition_height( $match, $operator, $value ) {
658
-
659
- if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
660
-
661
- foreach ( WC()->cart->cart_contents as $product ) :
662
-
663
- if ( true == $product['data']->variation_has_height ) :
664
- $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) );
665
- else :
666
- $height[] = ( get_post_meta( $product['product_id'], '_height', true ) );
667
- endif;
668
-
669
- endforeach;
670
-
671
- $max_height = max( $height );
672
-
673
- if ( '==' == $operator ) :
674
- $match = ( $max_height == $value );
675
- elseif ( '!=' == $operator ) :
676
- $match = ( $max_height != $value );
677
- elseif ( '>=' == $operator ) :
678
- $match = ( $max_height >= $value );
679
- elseif ( '<=' == $operator ) :
680
- $match = ( $max_height <= $value );
681
- endif;
682
-
683
- return $match;
684
-
685
- }
686
-
687
-
688
- /**
689
- * Length.
690
- *
691
- * Match the condition value against the lenghtiest product in the cart.
692
- *
693
- * @since 1.0.0
694
- *
695
- * @param bool $match Current match value.
696
- * @param string $operator Operator selected by the user in the condition row.
697
- * @param mixed $value Value given by the user in the condition row.
698
- * @return bool Matching result, true if results match, otherwise false.
699
- */
700
- public function wafs_match_condition_length( $match, $operator, $value ) {
701
-
702
- if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
703
-
704
- foreach ( WC()->cart->cart_contents as $product ) :
705
-
706
- if ( true == $product['data']->variation_has_length ) :
707
- $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) );
708
- else :
709
- $length[] = ( get_post_meta( $product['product_id'], '_length', true ) );
710
- endif;
711
-
712
- endforeach;
713
-
714
- $max_length = max( $length );
715
-
716
- if ( '==' == $operator ) :
717
- $match = ( $max_length == $value );
718
- elseif ( '!=' == $operator ) :
719
- $match = ( $max_length != $value );
720
- elseif ( '>=' == $operator ) :
721
- $match = ( $max_length >= $value );
722
- elseif ( '<=' == $operator ) :
723
- $match = ( $max_length <= $value );
724
- endif;
725
-
726
- return $match;
727
-
728
- }
729
-
730
-
731
- /**
732
- * Product stock.
733
- *
734
- * Match the condition value against all cart products stock.
735
- *
736
- * @since 1.0.0
737
- *
738
- * @param bool $match Current match value.
739
- * @param string $operator Operator selected by the user in the condition row.
740
- * @param mixed $value Value given by the user in the condition row.
741
- * @return bool Matching result, true if results match, otherwise false.
742
- */
743
- public function wafs_match_condition_stock( $match, $operator, $value ) {
744
-
745
- if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
746
-
747
- foreach ( WC()->cart->cart_contents as $product ) :
748
-
749
- $product_id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
750
- $stock[] = get_post_meta( $product_id, '_stock', true );
751
-
752
- endforeach;
753
-
754
- $min_stock = min( $stock );
755
-
756
- if ( '==' == $operator ) :
757
- $match = ( $min_stock == $value );
758
- elseif ( '!=' == $operator ) :
759
- $match = ( $min_stock != $value );
760
- elseif ( '>=' == $operator ) :
761
- $match = ( $min_stock >= $value );
762
- elseif ( '<=' == $operator ) :
763
- $match = ( $min_stock <= $value );
764
- endif;
765
-
766
- return $match;
767
-
768
- }
769
-
770
-
771
- /**
772
- * Stock status.
773
- *
774
- * Match the condition value against all cart products stock statuses.
775
- *
776
- * @since 1.0.0
777
- *
778
- * @param bool $match Current match value.
779
- * @param string $operator Operator selected by the user in the condition row.
780
- * @param mixed $value Value given by the user in the condition row.
781
- * @return bool Matching result, true if results match, otherwise false.
782
- */
783
- public function wafs_match_condition_stock_status( $match, $operator, $value ) {
784
-
785
- if ( ! isset( WC()->cart ) ) return $match;
786
-
787
- if ( '==' == $operator ) :
788
-
789
- $match = true;
790
- foreach ( WC()->cart->cart_contents as $product ) :
791
- if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value ) {
792
- $match = false;
793
- }
794
- endforeach;
795
-
796
- elseif ( '!=' == $operator ) :
797
-
798
- $match = true;
799
- foreach ( WC()->cart->cart_contents as $product ) :
800
- if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value ) {
801
- $match = false;
802
- }
803
- endforeach;
804
-
805
- endif;
806
-
807
- return $match;
808
-
809
- }
810
-
811
-
812
- /**
813
- * Category.
814
- *
815
- * Match the condition value against all the cart products category.
816
- * With this condition, all the products in the cart must have the given class.
817
- *
818
- * @since 1.0.0
819
- *
820
- * @param bool $match Current match value.
821
- * @param string $operator Operator selected by the user in the condition row.
822
- * @param mixed $value Value given by the user in the condition row.
823
- * @return bool Matching result, true if results match, otherwise false.
824
- */
825
- public function wafs_match_condition_category( $match, $operator, $value ) {
826
-
827
- if ( ! isset( WC()->cart ) ) return $match;
828
-
829
- $match = true;
830
-
831
- if ( '==' == $operator ) :
832
-
833
- foreach ( WC()->cart->cart_contents as $product ) :
834
-
835
- if ( ! has_term( $value, 'product_cat', $product['product_id'] ) ) :
836
- $match = false;
837
- endif;
838
-
839
- endforeach;
840
-
841
- elseif ( '!=' == $operator ) :
842
-
843
- foreach ( WC()->cart->cart_contents as $product ) :
844
-
845
- if ( has_term( $value, 'product_cat', $product['product_id'] ) ) :
846
- $match = false;
847
- endif;
848
-
849
- endforeach;
850
-
851
- endif;
852
-
853
- return $match;
854
-
855
- }
856
-
857
-
858
  }
19
  * @since 1.0.0
20
  */
21
  public function __construct() {
 
 
 
 
 
 
 
 
 
 
22
  add_filter( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  /**
27
  * Zipcode.
28
  *
121
  }
122
 
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  }
includes/class-wafs-method.php CHANGED
@@ -19,8 +19,6 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
19
  $this->method_title = __( 'Advanced Free Shipping', 'woocommerce-advanced-free-shipping' );
20
  $this->method_description = __( 'Configure Advanced Free Shipping' );
21
 
22
- $this->matched_methods = $this->wafs_match_methods();
23
-
24
  $this->init();
25
 
26
  }
@@ -63,16 +61,13 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
63
 
64
  $methods = wafs_get_rates();
65
 
66
- $matched_methods = '';
67
  foreach ( $methods as $method ) :
68
 
69
  $condition_groups = get_post_meta( $method->ID, '_wafs_shipping_method_conditions', true );
70
 
71
- // Check if method conditions match
72
- $match = $this->wafs_match_conditions( $condition_groups );
73
-
74
- // Add (single) match to parameter
75
- if ( true == $match ) :
76
  $matched_methods = $method->ID;
77
  endif;
78
 
@@ -83,46 +78,6 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
83
  }
84
 
85
 
86
- /**
87
- * Match conditions.
88
- *
89
- * Method to check all condition groups and conditions if they match their rules.
90
- *
91
- * @since 1.0.0
92
- *
93
- * @param array $condition_groups All condition groups set by the user.
94
- * @return bool true if one of the conditions groups matches.
95
- */
96
- public function wafs_match_conditions( $condition_groups = array() ) {
97
-
98
- if ( empty( $condition_groups ) ) return false;
99
-
100
- foreach ( $condition_groups as $condition_group => $conditions ) :
101
-
102
- $match_condition_group = true;
103
-
104
- foreach ( $conditions as $condition ) :
105
-
106
- $match = apply_filters( 'wafs_match_condition_' . $condition['condition'], false, $condition['operator'], $condition['value'] );
107
-
108
- if ( false == $match ) :
109
- $match_condition_group = false;
110
- endif;
111
-
112
- endforeach;
113
-
114
- // return true if one condition group matches
115
- if ( true == $match_condition_group ) :
116
- return true;
117
- endif;
118
-
119
- endforeach;
120
-
121
- return false;
122
-
123
- }
124
-
125
-
126
  /**
127
  * Init fields.
128
  *
@@ -165,34 +120,12 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
165
  public function generate_conditions_table_html() {
166
 
167
  ob_start();
168
-
169
- /**
170
- * Load conditions table file
171
- */
172
  require_once plugin_dir_path( __FILE__ ) . 'admin/views/conditions-table.php';
173
-
174
  return ob_get_clean();
175
 
176
  }
177
 
178
 
179
- /**
180
- * Validate table.
181
- *
182
- * Condition table does not need validation, so always return false.
183
- *
184
- * @since 1.0.0
185
- *
186
- * @param mixed $key Key.
187
- * @return bool Validation.
188
- */
189
- public function validate_additional_conditions_table_field( $key ) {
190
-
191
- return false;
192
-
193
- }
194
-
195
-
196
  /**
197
  * Calculate shipping.
198
  *
@@ -204,9 +137,15 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
204
  */
205
  public function calculate_shipping( $package = array() ) {
206
 
207
- if ( false == $this->matched_methods || 'no' == $this->enabled ) return;
 
 
 
 
 
 
208
 
209
- $method_args = get_post_meta( $this->matched_methods, '_wafs_shipping_method', true );
210
  $label = ! empty( $method_args['shipping_title'] ) ? $method_args['shipping_title'] : __( 'Free Shipping', 'woocommerce-advanced-free-shipping' );
211
 
212
  $rate = array(
19
  $this->method_title = __( 'Advanced Free Shipping', 'woocommerce-advanced-free-shipping' );
20
  $this->method_description = __( 'Configure Advanced Free Shipping' );
21
 
 
 
22
  $this->init();
23
 
24
  }
61
 
62
  $methods = wafs_get_rates();
63
 
64
+ $matched_methods = false;
65
  foreach ( $methods as $method ) :
66
 
67
  $condition_groups = get_post_meta( $method->ID, '_wafs_shipping_method_conditions', true );
68
 
69
+ // Check if conditions match
70
+ if ( wpc_match_conditions( $condition_groups, array( 'context' => 'wafs' ) ) ) :
 
 
 
71
  $matched_methods = $method->ID;
72
  endif;
73
 
78
  }
79
 
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  /**
82
  * Init fields.
83
  *
120
  public function generate_conditions_table_html() {
121
 
122
  ob_start();
 
 
 
 
123
  require_once plugin_dir_path( __FILE__ ) . 'admin/views/conditions-table.php';
 
124
  return ob_get_clean();
125
 
126
  }
127
 
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  /**
130
  * Calculate shipping.
131
  *
137
  */
138
  public function calculate_shipping( $package = array() ) {
139
 
140
+ if ( $this->enabled == 'no' ) {
141
+ return;
142
+ }
143
+
144
+ if ( ! $matched_rate = $this->wafs_match_methods() ) {
145
+ return;
146
+ }
147
 
148
+ $method_args = get_post_meta( $matched_rate, '_wafs_shipping_method', true );
149
  $label = ! empty( $method_args['shipping_title'] ) ? $method_args['shipping_title'] : __( 'Free Shipping', 'woocommerce-advanced-free-shipping' );
150
 
151
  $rate = array(
includes/class-wafs-post-type.php CHANGED
@@ -26,7 +26,6 @@ class WAFS_post_type {
26
  // Add/save meta boxes
27
  add_action( 'add_meta_boxes', array( $this, 'post_type_meta_box' ) );
28
  add_action( 'save_post', array( $this, 'save_meta' ) );
29
- add_action( 'save_post', array( $this, 'save_condition_meta' ) );
30
 
31
  // Edit user messages
32
  add_filter( 'post_updated_messages', array( $this, 'custom_post_type_messages' ) );
@@ -47,16 +46,16 @@ class WAFS_post_type {
47
  public function register_post_type() {
48
 
49
  $labels = array(
50
- 'name' => __( 'Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
51
- 'singular_name' => __( 'Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
52
  'add_new' => __( 'Add New', 'woocommerce-advanced-free-shipping' ),
53
- 'add_new_item' => __( 'Add New Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
54
- 'edit_item' => __( 'Edit Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
55
- 'new_item' => __( 'New Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
56
- 'view_item' => __( 'View Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
57
- 'search_items' => __( 'Search Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
58
- 'not_found' => __( 'No Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
59
- 'not_found_in_trash' => __( 'No Advanced Free Shipping methods found in Trash', 'woocommerce-advanced-free-shipping' ),
60
  );
61
 
62
  register_post_type( 'wafs', array(
@@ -94,22 +93,22 @@ class WAFS_post_type {
94
 
95
  $messages['wafs'] = array(
96
  0 => '',
97
- 1 => __( 'Free shipping method updated.', 'woocommerce-advanced-free-shipping' ),
98
  2 => __( 'Custom field updated.', 'woocommerce-advanced-free-shipping' ),
99
  3 => __( 'Custom field deleted.', 'woocommerce-advanced-free-shipping' ),
100
- 4 => __( 'Free shipping method updated.', 'woocommerce-advanced-free-shipping' ),
101
- 6 => __( 'Free shipping method published.', 'woocommerce-advanced-free-shipping' ),
102
- 7 => __( 'Free shipping method saved.', 'woocommerce-advanced-free-shipping' ),
103
- 8 => __( 'Free shipping method submitted.', 'woocommerce-advanced-free-shipping' ),
104
  9 => sprintf(
105
  __( 'Free shipping method scheduled for: <strong>%1$s</strong>.', 'woocommerce-advanced-free-shipping' ),
106
  date_i18n( __( 'M j, Y @ G:i', 'woocommerce-advanced-free-shipping' ), strtotime( $post->post_date ) )
107
  ),
108
- 10 => __( 'Free shipping method draft updated.', 'woocommerce-advanced-free-shipping' ),
109
  );
110
 
111
  if ( 'wafs' == $post_type ) :
112
- $overview_link = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=wafs_free_shipping_method' );
113
 
114
  $overview = sprintf( ' <a href="%s">%s</a>', esc_url( $overview_link ), __( 'Return to overview.', 'woocommerce-advanced-free-shipping' ) );
115
  $messages[ $post_type ][1] .= $overview;
@@ -148,12 +147,7 @@ class WAFS_post_type {
148
  * @since 1.0.0
149
  */
150
  public function render_wafs_conditions() {
151
-
152
- /**
153
- * Load meta box conditions view.
154
- */
155
  require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-conditions.php';
156
-
157
  }
158
 
159
 
@@ -165,40 +159,7 @@ class WAFS_post_type {
165
  * @since 1.0.0
166
  */
167
  public function render_wafs_settings() {
168
-
169
- /**
170
- * Load meta box settings view
171
- */
172
  require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-settings.php';
173
-
174
- }
175
-
176
-
177
- /**
178
- * Save conditions meta box.
179
- *
180
- * Validate and save post meta from conditions meta box.
181
- *
182
- * @since 1.0.0
183
- */
184
- public function save_condition_meta( $post_id ) {
185
-
186
- if ( ! isset( $_POST['wafs_settings_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wafs_settings_meta_box_nonce'], 'wafs_settings_meta_box' ) ) :
187
- return $post_id;
188
- endif;
189
-
190
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) :
191
- return $post_id;
192
- endif;
193
-
194
- if ( ! current_user_can( 'manage_woocommerce' ) ) :
195
- return $post_id;
196
- endif;
197
-
198
- $shipping_method_conditions = $_POST['conditions'];
199
-
200
- update_post_meta( $post_id, '_wafs_shipping_method_conditions', $shipping_method_conditions );
201
-
202
  }
203
 
204
 
@@ -224,9 +185,11 @@ class WAFS_post_type {
224
  endif;
225
 
226
  $shipping_method = array_map( 'sanitize_text_field', $_POST['_wafs_shipping_method'] );
227
-
228
  update_post_meta( $post_id, '_wafs_shipping_method', $shipping_method );
229
 
 
 
 
230
  }
231
 
232
 
26
  // Add/save meta boxes
27
  add_action( 'add_meta_boxes', array( $this, 'post_type_meta_box' ) );
28
  add_action( 'save_post', array( $this, 'save_meta' ) );
 
29
 
30
  // Edit user messages
31
  add_filter( 'post_updated_messages', array( $this, 'custom_post_type_messages' ) );
46
  public function register_post_type() {
47
 
48
  $labels = array(
49
+ 'name' => __( 'Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ),
50
+ 'singular_name' => __( 'Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ),
51
  'add_new' => __( 'Add New', 'woocommerce-advanced-free-shipping' ),
52
+ 'add_new_item' => __( 'Add New Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ),
53
+ 'edit_item' => __( 'Edit Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ),
54
+ 'new_item' => __( 'New Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ),
55
+ 'view_item' => __( 'View Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ),
56
+ 'search_items' => __( 'Search Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ),
57
+ 'not_found' => __( 'No Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ),
58
+ 'not_found_in_trash' => __( 'No Advanced Free Shipping rates found in Trash', 'woocommerce-advanced-free-shipping' ),
59
  );
60
 
61
  register_post_type( 'wafs', array(
93
 
94
  $messages['wafs'] = array(
95
  0 => '',
96
+ 1 => __( 'Free shipping rate updated.', 'woocommerce-advanced-free-shipping' ),
97
  2 => __( 'Custom field updated.', 'woocommerce-advanced-free-shipping' ),
98
  3 => __( 'Custom field deleted.', 'woocommerce-advanced-free-shipping' ),
99
+ 4 => __( 'Free shipping rate updated.', 'woocommerce-advanced-free-shipping' ),
100
+ 6 => __( 'Free shipping rate published.', 'woocommerce-advanced-free-shipping' ),
101
+ 7 => __( 'Free shipping rate saved.', 'woocommerce-advanced-free-shipping' ),
102
+ 8 => __( 'Free shipping rate submitted.', 'woocommerce-advanced-free-shipping' ),
103
  9 => sprintf(
104
  __( 'Free shipping method scheduled for: <strong>%1$s</strong>.', 'woocommerce-advanced-free-shipping' ),
105
  date_i18n( __( 'M j, Y @ G:i', 'woocommerce-advanced-free-shipping' ), strtotime( $post->post_date ) )
106
  ),
107
+ 10 => __( 'Free shipping rate draft updated.', 'woocommerce-advanced-free-shipping' ),
108
  );
109
 
110
  if ( 'wafs' == $post_type ) :
111
+ $overview_link = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=advanced_free_shipping' );
112
 
113
  $overview = sprintf( ' <a href="%s">%s</a>', esc_url( $overview_link ), __( 'Return to overview.', 'woocommerce-advanced-free-shipping' ) );
114
  $messages[ $post_type ][1] .= $overview;
147
  * @since 1.0.0
148
  */
149
  public function render_wafs_conditions() {
 
 
 
 
150
  require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-conditions.php';
 
151
  }
152
 
153
 
159
  * @since 1.0.0
160
  */
161
  public function render_wafs_settings() {
 
 
 
 
162
  require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-settings.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  }
164
 
165
 
185
  endif;
186
 
187
  $shipping_method = array_map( 'sanitize_text_field', $_POST['_wafs_shipping_method'] );
 
188
  update_post_meta( $post_id, '_wafs_shipping_method', $shipping_method );
189
 
190
+ // Save sanitized conditions
191
+ update_post_meta( $post_id, '_wafs_shipping_method_conditions', wpc_sanitize_conditions( $_POST['conditions'] ) );
192
+
193
  }
194
 
195
 
includes/core-functions.php CHANGED
@@ -19,12 +19,63 @@ function wafs_get_rates( $args = array() ) {
19
  'posts_per_page' => 1000,
20
  'orderby' => 'menu_order',
21
  'order' => 'ASC',
22
- 'update_post_term_cache' => false
 
23
  ) );
24
 
25
  $rates_query = new WP_Query( $query_args );
26
- $shipping_rates = $rates_query->get_posts();
27
 
28
  return apply_filters( 'woocommerce_advanced_free_shipping_get_rates', $shipping_rates );
29
 
30
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  'posts_per_page' => 1000,
20
  'orderby' => 'menu_order',
21
  'order' => 'ASC',
22
+ 'update_post_term_cache' => false,
23
+ 'no_found_rows' => true,
24
  ) );
25
 
26
  $rates_query = new WP_Query( $query_args );
27
+ $shipping_rates = $rates_query->posts;
28
 
29
  return apply_filters( 'woocommerce_advanced_free_shipping_get_rates', $shipping_rates );
30
 
31
  }
32
+
33
+ /**************************************************************
34
+ * Backwards compatibility for WP Conditions
35
+ *************************************************************/
36
+
37
+ /**
38
+ * Add the filters required for backwards-compatibility for the matching functionality.
39
+ *
40
+ * @since 1.1.0
41
+ */
42
+ function wafs_add_bc_filter_condition_match( $match, $condition, $operator, $value, $args = array() ) {
43
+
44
+ if ( ! isset( $args['context'] ) || $args['context'] != 'wafs' ) {
45
+ return $match;
46
+ }
47
+
48
+ if ( has_filter( 'wafs_match_condition_' . $condition ) ) {
49
+ $match = apply_filters( 'wafs_match_condition_' . $condition, $match = false, $operator, $value );
50
+ }
51
+
52
+ return $match;
53
+
54
+ }
55
+ add_action( 'wp-conditions\condition\match', 'wafs_add_bc_filter_condition_match', 10, 5 );
56
+
57
+
58
+ /**
59
+ * Add condition descriptions of custom conditions.
60
+ *
61
+ * @since 1.1.0
62
+ */
63
+ function wafs_add_bc_filter_condition_descriptions( $descriptions ) {
64
+ return apply_filters( 'wafs_descriptions', $descriptions );
65
+ }
66
+ add_filter( 'wp-conditions\condition_descriptions', 'wafs_add_bc_filter_condition_descriptions' );
67
+
68
+
69
+ /**
70
+ * Add custom field BC.
71
+ *
72
+ * @since 1.1.0
73
+ */
74
+ function wafs_add_bc_action_custom_fields( $type, $args ) {
75
+
76
+ if ( has_action( 'woocommerce_advanced_fees_condition_value_field_type_' . $type ) ) {
77
+ do_action( 'woocommerce_advanced_fees_condition_value_field_type_' . $args['type'], $args );
78
+ }
79
+
80
+ }
81
+ add_action( 'wp-conditions\html_field_hook', 'wafs_add_bc_action_custom_fields' );
libraries/wp-conditions/admin-functions.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+
5
+ if ( ! function_exists( 'wpc_admin_enqueue_scripts' ) ) {
6
+
7
+ /**
8
+ * Register scripts.
9
+ *
10
+ * Register the general WPC scripts that can be used as a dependency.
11
+ *
12
+ * @since 1.0.0
13
+ */
14
+ function wpc_admin_enqueue_scripts() {
15
+
16
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
17
+
18
+ wp_register_script( 'wpc-repeater', plugins_url( 'assets/js/repeater/jquery.repeater' . $suffix . '.js', __FILE__ ), array( 'jquery' ), '1.0.0', true );
19
+ wp_register_script( 'wp-conditions', plugins_url( 'assets/js/wp-conditions' . $suffix . '.js', __FILE__ ), array( 'jquery', 'wpc-repeater', 'select2' ), '1.0.0', true );
20
+
21
+ wp_localize_script( 'wp-conditions', 'wpc', array(
22
+ 'nonce' => wp_create_nonce( 'wpc-ajax-nonce' ),
23
+ 'condition_operators' => wpc_condition_operators(),
24
+ 'condition_descriptions' => wpc_condition_descriptions(),
25
+ ) );
26
+
27
+ }
28
+ add_action( 'admin_enqueue_scripts', 'wpc_admin_enqueue_scripts', 5 );
29
+
30
+ }
31
+
32
+ if ( ! function_exists( 'wpc_html_field' ) ) {
33
+
34
+ /**
35
+ * Output html field.
36
+ *
37
+ * Output a new HTML field.
38
+ *
39
+ * @since 1.0.0
40
+ *
41
+ * @param array $args
42
+ */
43
+ function wpc_html_field( $args = array() ) {
44
+
45
+ $args = wp_parse_args( $args, array(
46
+ 'id' => '',
47
+ 'type' => 'text',
48
+ 'name' => '',
49
+ 'class' => '',
50
+ 'value' => null,
51
+ 'default' => '',
52
+ 'placeholder' => '',
53
+ 'custom_attributes' => isset( $args['custom_attr'] ) ? $args['custom_attr'] : array(), // BC
54
+ ) );
55
+
56
+ $type = ! empty( $args['field'] ) ? $args['field'] : $args['type'];
57
+ $class = is_array( $args['class'] ) ? implode( ' ', array_map( 'sanitize_html_class', $args['class'] ) ) : sanitize_html_class( $args['class'] );
58
+ $value = isset( $args['value'] ) ? $args['value'] : '';
59
+ $name = isset( $args['name'] ) ? $args['name'] : $args['id'];
60
+ $custom_attributes = array();
61
+ if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) {
62
+ foreach ( $args['custom_attributes'] as $k => $v ) {
63
+ $custom_attributes[ $k ] = esc_attr( $k ) . '="' . esc_attr( $v ) . '"';
64
+ }
65
+ }
66
+
67
+ switch ( $type ) :
68
+
69
+ case 'text' :
70
+ case 'number' :
71
+ ?><input
72
+ name="<?php echo esc_attr( $name ); ?>"
73
+ type="<?php echo $args['type']; ?>"
74
+ id="<?php echo esc_attr( $args['id'] ); ?>"
75
+ value="<?php echo esc_attr( $value ); ?>"
76
+ class="input-text <?php echo $class; ?>"
77
+ <?php echo implode( ' ', $custom_attributes ); ?>
78
+ placeholder='<?php echo esc_attr( $args['placeholder'] ); ?>'
79
+ ><?php
80
+ break;
81
+
82
+ case 'dropdown' :
83
+ case 'select' :
84
+
85
+ $options = is_array( $args['options'] ) ? $args['options'] : array();
86
+
87
+ ?><select
88
+ name="<?php echo esc_attr( $args['name'] ); ?>"
89
+ id="<?php echo esc_attr( $args['id'] ); ?>"
90
+ class="input-select <?php echo $class; ?>"
91
+ <?php echo implode( ' ', $custom_attributes ); ?>
92
+ ><?php
93
+
94
+ foreach ( $options as $index => $values ) :
95
+
96
+ if ( ! is_array( $values ) ) :
97
+ ?><option value='<?php echo esc_attr( $index ); ?>' <?php selected( $index, $value ); ?>><?php echo esc_attr( $values ); ?></option><?php
98
+ else :
99
+ ?><optgroup label='<?php echo esc_attr( $index ); ?>'><?php
100
+ foreach ( $values as $k => $v ) :
101
+ ?><option value='<?php echo esc_attr( $k ); ?>' <?php selected( $k, $value ); ?>><?php echo esc_attr( $v ); ?></option><?php
102
+ endforeach;
103
+ ?></optgroup><?php
104
+ endif;
105
+
106
+ endforeach;
107
+
108
+ if ( empty( $options ) ) :
109
+ ?><option readonly disabled><?php
110
+ _e( 'There are no options available', 'wp-conditions' );
111
+ ?></option><?php
112
+ endif;
113
+
114
+ ?></select><?php
115
+ break;
116
+
117
+ case 'product' :
118
+ if ( $product = wc_get_product( $value ) ) {
119
+ $args['custom_attributes']['data-selected'] = $product->get_formatted_name();
120
+ }
121
+ $args['type'] = 'text';
122
+ wpc_html_field( $args );
123
+ break;
124
+
125
+ default :
126
+ case 'hook' :
127
+
128
+ do_action( 'wp-conditions\html_field_hook', $args['type'], $args );
129
+ do_action( 'wp-conditions\html_field_type_' . $args['type'], $args );
130
+ break;
131
+
132
+ endswitch;
133
+
134
+ }
135
+
136
+
137
+ }
138
+
139
+
140
+ if ( ! function_exists( 'wpc_ajax_save_post_order' ) ) {
141
+
142
+ /**
143
+ * Save post order.
144
+ *
145
+ * Save the order of the posts in the overview table.
146
+ *
147
+ * @since 1.0.0
148
+ */
149
+ function wpc_ajax_save_post_order() {
150
+
151
+ global $wpdb;
152
+
153
+ check_ajax_referer( 'wpc-ajax-nonce', 'nonce' );
154
+
155
+ $args = wp_parse_args( $_POST['form'] );
156
+
157
+ if ( ! isset( $args['sort'] ) ) {
158
+ die( '-1' );
159
+ }
160
+
161
+ $menu_order = 0;
162
+ foreach ( $args['sort'] as $sort ) :
163
+
164
+ $wpdb->update(
165
+ $wpdb->posts,
166
+ array( 'menu_order' => $menu_order ),
167
+ array( 'ID' => $sort ),
168
+ array( '%d' ),
169
+ array( '%d' )
170
+ );
171
+
172
+ $menu_order++;
173
+
174
+ endforeach;
175
+
176
+ die;
177
+
178
+ }
179
+ add_action( 'wp_ajax_wpc_save_post_order', 'wpc_ajax_save_post_order' );
180
+
181
+ }
libraries/wp-conditions/assets/css/wp-conditions.min.css ADDED
@@ -0,0 +1 @@
 
1
+ .wpc-conditions .wpc-condition-group{background-color:#f5f5f5;padding:15px;border:1px solid #e5e5e5;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04);min-height:30px;margin:0 -13px 1.5em}.wpc-conditions .wpc-condition-group:hover .wpc-condition-group-actions{opacity:1}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions{opacity:0;margin:-10px -10px 0 0;font-size:80%}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a{text-decoration:none}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete{color:#a00}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete:hover{color:#f00}.wpc-conditions .wpc-condition-group .wpc-condition-wrap{margin:10px 0 5px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-condition{width:35%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-operator{width:22.5%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-value{width:calc( 42.5% - 75px );height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description{float:right}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip{height:28px;line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip:after{line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap input{vertical-align:top}.wpc-conditions .clearfix:after{content:" ";display:block;height:0;clear:both}.wpc-conditions .wpc-add.button:before{font-family:'dashicons';content:"\f502";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;margin-right:5px;color:#667}.wpc-conditions .wpc-condition-delete.button{font-weight:600;width:30px;text-align:center;padding:0}.wpc-conditions .wpc-condition-delete.button:before{font-family:'dashicons';content:"\f460";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;color:#667}.wpc-conditions>p+.wpc-condition-group-wrap p.or-text{display:none}.wpc-conditions .or-text{margin:1.5em 0}.wpc-conditions .match-text{margin:0 0 1em}.wpc-conditions .wpc-condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wpc-conditions .wpc-condition-wrap:hover .wpc-condition-delete{display:inline-block;opacity:1}.wpc-conditions .wpc-condition-wrap.loading{height:30px}.wpc-conditions .wpc-condition-wrap.loading .loading-icon{width:100%;clear:both;display:block;text-align:center;line-height:110%;margin:0 1px}.wpc-condition-wrap .wpc-value.select2-container{display:inline-block !important;margin:1px}.wpc-condition-wrap .wpc-value.select2-container.select2-container-active .select2-choice{border:1px solid #666}.wpc-condition-wrap .wpc-value.select2-container.select2-drop-above .select2-choice{border-radius:0 0 4px 4px;border:1px solid #666;border-top-color:transparent}.wpc-condition-wrap .wpc-value.select2-container .select2-choice{border-color:#ddd;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;height:26px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07)}.wpc-condition-wrap .wpc-value.select2-dropdown-open .select2-choice{border-bottom-color:transparent;-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset;border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid #666;outline:0}.wpc-conditions-post-table .sort{padding:0 4px;cursor:move;text-align:center;vertical-align:middle}.wpc-conditions-post-table .sort:before{content:"\e032";font-family:WooCommerce;text-align:center;line-height:1;color:#999;display:block;width:100%;float:left;height:100%}.wpc-conditions-post-table .sort:before,.wpc-conditions-post-table .row-actions{visibility:hidden !important}.wpc-conditions-post-table tr:hover .sort:before,.wpc-conditions-post-table tr:hover>td>.row-actions{visibility:visible !important}.wpc-conditions-post-table .add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}.wpc-currency{padding:3px 10px;font-size:14px;font-weight:400;line-height:19px;height:27px;box-sizing:border-box;color:#555;text-align:center;background-color:#EEE;border:1px solid #DDD;border-right:none;border-radius:4px 0px 0px 4px;margin:1px 0px 1px 1px;display:inline-block}.wpc-currency+input{margin-left:-4px;line-height:19px;width:161px !important}@media screen and (max-width: 782px){.wpc-currency{font-size:16px;padding:6px 10px;height:33px}}
{assets/css/parts → libraries/wp-conditions/assets/css}/wp-conditions.scss RENAMED
@@ -1,5 +1,5 @@
1
  /**
2
- * WPC 1.0.1
3
  */
4
 
5
  /**************************************************************
@@ -9,31 +9,64 @@
9
 
10
  // Condition group
11
  .wpc-condition-group {
12
- margin-bottom: 30px;
13
  background-color: #f5f5f5;
14
- padding: 15px 20px 20px;
15
- border: 1px solid #ddd;
16
  -webkit-box-shadow: 0 1px 1px rgba( 0, 0, 0, .04 );
17
  box-shadow: 0 1px 1px rgba( 0, 0, 0, .04 );
18
  min-height: 30px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  // Condition row
21
  .wpc-condition-wrap {
22
  margin: 10px 0 5px;
23
 
24
  .wpc-condition {
25
- width: 30%;
26
  }
27
  .wpc-operator {
28
- width: 12%;
29
- min-width: 140px;
30
  }
31
  .wpc-value {
32
- width: 30%;
33
  height: 28px;
34
  }
35
  .wpc-description {
36
  float: right;
 
 
 
 
 
 
 
 
 
37
  }
38
  input {
39
  vertical-align: top;
@@ -41,13 +74,53 @@
41
  }
42
  }
43
 
44
- // Or text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  .or-text {
46
- display: none !important;
47
  }
48
- .wpc-condition-group ~ .or-text,
49
- .wpc-condition-group ~ .or-text ~ .wpc-condition-group .or-text { // Ensures the one in the first group isn't shown
50
- display: block !important;
51
  }
52
 
53
  // Delete button
@@ -113,8 +186,18 @@
113
  border: 1px solid #666;
114
  outline: 0;
115
  }
116
- }
117
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  /************************
120
  * Table / overview
@@ -161,7 +244,20 @@
161
  content: "\e007";
162
  }
163
  }
 
 
164
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
  // Currency
167
  .wpc-currency {
@@ -185,4 +281,10 @@
185
  line-height: 19px ;
186
  width: 161px !important;
187
  }
 
 
 
 
 
 
188
  }
1
  /**
2
+ * WP-Conditions 1.0.0
3
  */
4
 
5
  /**************************************************************
9
 
10
  // Condition group
11
  .wpc-condition-group {
 
12
  background-color: #f5f5f5;
13
+ padding: 15px;
14
+ border: 1px solid #e5e5e5;
15
  -webkit-box-shadow: 0 1px 1px rgba( 0, 0, 0, .04 );
16
  box-shadow: 0 1px 1px rgba( 0, 0, 0, .04 );
17
  min-height: 30px;
18
+ margin: 0 -13px 1.5em;
19
+
20
+ &:hover {
21
+ .wpc-condition-group-actions {
22
+ opacity: 1;
23
+ }
24
+ }
25
+
26
+ .wpc-condition-group-actions {
27
+ opacity: 0;
28
+ margin: -10px -10px 0 0;
29
+ font-size: 80%;
30
+
31
+ a {
32
+ text-decoration: none;
33
+
34
+ &.delete {
35
+ color: #a00;
36
+
37
+ &:hover {
38
+ color: #f00;
39
+ }
40
+ }
41
+ }
42
+ }
43
 
44
  // Condition row
45
  .wpc-condition-wrap {
46
  margin: 10px 0 5px;
47
 
48
  .wpc-condition {
49
+ width: 35%;
50
  }
51
  .wpc-operator {
52
+ width: 22.5%;
53
+ //min-width: 140px;
54
  }
55
  .wpc-value {
56
+ width: calc( 42.5% - 75px );
57
  height: 28px;
58
  }
59
  .wpc-description {
60
  float: right;
61
+
62
+ .woocommerce-help-tip {
63
+ height: 28px;
64
+ line-height: 28px;
65
+
66
+ &:after {
67
+ line-height: 28px;
68
+ }
69
+ }
70
  }
71
  input {
72
  vertical-align: top;
74
  }
75
  }
76
 
77
+ .clearfix:after {
78
+ content: " ";
79
+ display: block;
80
+ height: 0;
81
+ clear: both;
82
+ }
83
+
84
+ /* Add / delete icon */
85
+ .wpc-add.button {
86
+ //font-weight: 500;
87
+
88
+ &:before {
89
+ font-family: 'dashicons';
90
+ content: "\f502";
91
+ vertical-align: middle;
92
+ height: 1.2em;
93
+ line-height: 1;
94
+ display: inline-block;
95
+ margin-right: 5px;
96
+ color: #667;
97
+ }
98
+ }
99
+ .wpc-condition-delete.button {
100
+ font-weight: 600;
101
+ width: 30px;
102
+ text-align: center;
103
+ padding: 0;
104
+
105
+ &:before {
106
+ font-family: 'dashicons';
107
+ content: "\f460";
108
+ vertical-align: middle;
109
+ height: 1.2em;
110
+ line-height: 1;
111
+ display: inline-block;
112
+ color: #667;
113
+ }
114
+ }
115
+
116
+ & > p + .wpc-condition-group-wrap p.or-text {
117
+ display: none;
118
+ }
119
  .or-text {
120
+ margin: 1.5em 0;
121
  }
122
+ .match-text {
123
+ margin: 0 0 1em;
 
124
  }
125
 
126
  // Delete button
186
  border: 1px solid #666;
187
  outline: 0;
188
  }
 
189
 
190
+ // WC 2.7+
191
+ .select2-container .select2-selection--single {
192
+ height: 28px !important;
193
+
194
+ #select2--container,
195
+ .select2-selection__arrow {
196
+ line-height: 26px;
197
+ }
198
+ .select2-selection__arrow { height: 28px; }
199
+ }
200
+ }
201
 
202
  /************************
203
  * Table / overview
244
  content: "\e007";
245
  }
246
  }
247
+ @media screen and (max-width: 782px) {
248
+ .wpc-conditions-post-table {
249
 
250
+ th {
251
+ padding: 8px;
252
+ }
253
+ td {
254
+ padding: 8px 10px;
255
+ }
256
+ tfoot .button {
257
+ margin-bottom: 0;
258
+ }
259
+ }
260
+ }
261
 
262
  // Currency
263
  .wpc-currency {
281
  line-height: 19px ;
282
  width: 161px !important;
283
  }
284
+
285
+ @media screen and (max-width: 782px) {
286
+ font-size: 16px;
287
+ padding: 6px 10px;
288
+ height: 33px;
289
+ }
290
  }
libraries/wp-conditions/assets/js/repeater/jquery.repeater.js ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($) {
2
+
3
+ $.fn.repeater = function(options) {
4
+
5
+ var defaults = {
6
+ addTrigger: '.repeater-add',
7
+ removeTrigger: '.repeater-remove',
8
+ template: '.repeater-template',
9
+ elementWrap: '.repeater-row', // Used to identify what is one element within the container.
10
+ elementsContainer: '.repeater-container', // Used to identify what is one element within the container.
11
+ removeElement: undefined,
12
+ };
13
+
14
+ return $( this ).filter( ':not(.repeater-active)' ).each( function(i, e) {
15
+ $( this ).addClass( 'repeater-active' );
16
+
17
+ var $self;
18
+ var $container;
19
+
20
+ options = $.extend({}, $.fn.repeater.defaults, options);
21
+
22
+ var init = function() {
23
+ $container = $self.find( options.elementsContainer );
24
+
25
+ $self.on( 'click', options.addTrigger, function(e) {
26
+ e.preventDefault();
27
+ addElement();
28
+ });
29
+ $self.on( 'click', options.removeTrigger, function() {
30
+ removeElement( $(this).parents( options.elementWrap ).first() );
31
+ });
32
+ };
33
+
34
+ var getTemplate = function() {
35
+ return $self.find( options.template ).first().clone();
36
+ };
37
+
38
+ var addElement = function() {
39
+ var template = getTemplate();
40
+
41
+ $container.append( template );
42
+ $( document.body ).trigger( 'repeater-added-row', [template, $container, $self] );
43
+ };
44
+
45
+ var removeElement = options.removeElement || function( el ) {
46
+ el.slideUp( 'fast', function() { $(this).remove() });
47
+ };
48
+
49
+ $self = $(this);
50
+ init();
51
+
52
+ return $self;
53
+ });
54
+
55
+ }
56
+
57
+ })(jQuery);
libraries/wp-conditions/assets/js/repeater/jquery.repeater.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function($){$.fn.repeater=function(e){var r={addTrigger:".repeater-add",removeTrigger:".repeater-remove",template:".repeater-template",elementWrap:".repeater-row",elementsContainer:".repeater-container",removeElement:void 0};return $(this).filter(":not(.repeater-active)").each(function(r,t){$(this).addClass("repeater-active");var n,a;e=$.extend({},$.fn.repeater.defaults,e);var i=function(){a=n.find(e.elementsContainer),n.on("click",e.addTrigger,function(e){e.preventDefault(),c()}),n.on("click",e.removeTrigger,function(){d($(this).parents(e.elementWrap).first())})},o=function(){return n.find(e.template).first().clone()},c=function(){var e=o();a.append(e),$(document.body).trigger("repeater-added-row",[e,a,n])},d=e.removeElement||function(e){e.slideUp("fast",function(){$(this).remove()})};return n=$(this),i(),n})}}(jQuery);
libraries/wp-conditions/assets/js/wp-conditions.js ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery( function( $ ) {
2
+
3
+ function wpc_condition_group_repeater() {
4
+ // Condition group repeater
5
+ $( '.wpc-conditions' ).parents( '.postbox' ).repeater({
6
+ addTrigger: '.wpc-condition-group-add',
7
+ removeTrigger: '.wpc-condition-group .delete',
8
+ template: '.wpc-condition-group-template .wpc-condition-group-wrap',
9
+ elementWrap: '.wpc-condition-group-wrap',
10
+ elementsContainer: '.wpc-conditions',
11
+ removeElement: function( el ) {
12
+ el.remove();
13
+ }
14
+ });
15
+ }
16
+ wpc_condition_group_repeater();
17
+
18
+
19
+ function wpc_condition_row_repeater() {
20
+ // Condition repeater
21
+ $( '.wpc-condition-group' ).repeater({
22
+ addTrigger: '.wpc-condition-add',
23
+ removeTrigger: '.wpc-condition-delete',
24
+ template: '.wpc-condition-template .wpc-condition-wrap',
25
+ elementWrap: '.wpc-condition-wrap',
26
+ elementsContainer: '.wpc-conditions-list',
27
+ });
28
+ }
29
+ wpc_condition_row_repeater();
30
+
31
+
32
+ // Assign new ID to repeater row + open collapsible + re-enable nested repeater
33
+ jQuery( document.body ).on( 'repeater-added-row', function( e, template, container, $self ) {
34
+ var new_id = Math.floor(Math.random()*8999999999+1000000000); // Random number sequence of 10 length
35
+ template.find( 'input[name], select[name]' ).attr( 'name', function( index, value ) {
36
+ return ( value.replace( '9999', new_id ) ) || value;
37
+ });
38
+ template.find( '.wpc-condition[data-id]' ).attr( 'data-id', function( index, value ) {
39
+ return ( value.replace( '9999', new_id ) ) || value;
40
+ });
41
+ template.find( '[data-group]' ).attr( 'data-group', function( index, value ) {
42
+ return ( value.replace( '9999', new_id ) ) || value;
43
+ });
44
+
45
+ template.find( '.repeater-active' ).removeClass( 'repeater-active' );
46
+
47
+ // Init condition group repeater
48
+ wpc_condition_row_repeater();
49
+ });
50
+
51
+
52
+ // Duplicate condition group
53
+ $( document.body ).on ( 'click', '.wpc-conditions .duplicate', function() {
54
+ var condition_group_wrap = $( this ).parents( '.wpc-condition-group-wrap' ),
55
+ condition_group_id = condition_group_wrap.find( '.wpc-condition-group' ).attr( 'data-group' ),
56
+ condition_group_list = $( this ).parents( '.wpc-conditions' ),
57
+ new_group = condition_group_wrap.clone(),
58
+ new_group_id = Math.floor(Math.random()*8999999999+1000000000); // Random number sequence of 10 length
59
+
60
+ // Fix dropdown selected not being cloned properly
61
+ $( condition_group_wrap ).find( 'select' ).each(function(i) {
62
+ $( new_group ).find( 'select' ).eq( i ).val( $( this ).val() );
63
+ });
64
+
65
+ // Assign proper names
66
+ new_group.find( '.wpc-condition-group' ).attr( 'data-group', new_group_id );
67
+ new_group.find( 'input[name], select[name]' ).attr( 'name', function( index, name ) {
68
+ return name.replace( 'conditions[' + condition_group_id + ']', 'conditions[' + new_group_id + ']' );
69
+ });
70
+
71
+ new_group.find( '.repeater-active' ).removeClass( 'repeater-active' );
72
+ condition_group_list.append( new_group );
73
+
74
+ // Enable Select2's
75
+ //$( document.body ).trigger( 'wc-enhanced-select-init' );
76
+
77
+ // Init condition repeater
78
+ wpc_condition_row_repeater();
79
+
80
+ // Stop autoscroll on manual scrolling
81
+ $( 'html, body' ).on( "scroll mousedown DOMMouseScroll mousewheel keydown touchmove", function( e ) {
82
+ $( 'html, body' ).stop().off('scroll mousedown DOMMouseScroll mousewheel keydown touchmove');
83
+ });
84
+
85
+ // Autoscroll to new group
86
+ $( 'body, html' ).animate({ scrollTop: $( new_group ).offset().top - 50 }, 750, function() {
87
+ $( 'html, body' ).off('scroll mousedown DOMMouseScroll mousewheel keydown touchmove');
88
+ });
89
+
90
+ });
91
+
92
+
93
+ // Update condition values
94
+ $( document.body ).on( 'change', '.wpc-condition', function () {
95
+
96
+ var loading_wrap = '<span style="width: calc( 42.5% - 75px ); border: 1px solid transparent; display: inline-block;">&nbsp;</span>';
97
+ var data = {
98
+ action: wpc2.action_prefix + 'update_condition_value',
99
+ id: $( this ).attr( 'data-id' ),
100
+ group: $( this ).parents( '.wpc-condition-group' ).attr( 'data-group' ),
101
+ condition: $( this ).val(),
102
+ nonce: wpc.nonce
103
+ };
104
+ var condition_wrap = $( this ).parents( '.wpc-condition-wrap' ).first();
105
+ var replace = '.wpc-value-field-wrap';
106
+
107
+ // Loading icon
108
+ condition_wrap.find( replace ).html( loading_wrap ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } });
109
+
110
+ // Replace value field
111
+ $.post( ajaxurl, data, function( response ) {
112
+ condition_wrap.find( replace ).replaceWith( response );
113
+ $( document.body ).trigger( 'wc-enhanced-select-init' );
114
+ });
115
+
116
+ // Update operators
117
+ var operator_value = condition_wrap.find( '.wpc-operator' ).val();
118
+ condition_wrap.find( '.wpc-operator' ).empty().html( function() {
119
+ var operator = $( this );
120
+ var available_operators = wpc.condition_operators[ data.condition] || wpc.condition_operators['default'];
121
+
122
+ $.each( available_operators, function( index, value ) {
123
+ operator.append( $('<option/>' ).attr( 'value', index ).text( value ) );
124
+ operator.val( operator_value ).val() || operator.val( operator.find( 'option:first' ).val() );
125
+ });
126
+ });
127
+
128
+ // Update condition description
129
+ condition_wrap.find( '.wpc-description' ).html( function() {
130
+ return $( '<span class="woocommerce-help-tip" />' ).attr( 'data-tip', ( wpc.condition_descriptions[ data.condition ] || '' ) );
131
+ });
132
+ $( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 200 });
133
+ $( '#tiptip_holder' ).removeAttr( 'style' );
134
+ $( '#tiptip_arrow' ).removeAttr( 'style' );
135
+
136
+ });
137
+
138
+
139
+ // Sortable post table
140
+ $( '.wpc-conditions-post-table.wpc-sortable-post-table tbody' ).sortable({
141
+ items: 'tr',
142
+ handle: '.sort',
143
+ cursor: 'move',
144
+ axis: 'y',
145
+ scrollSensitivity: 40,
146
+ forcePlaceholderSize: true,
147
+ helper: 'clone',
148
+ opacity: 0.65,
149
+ placeholder: 'wc-metabox-sortable-placeholder',
150
+ start: function(event,ui){
151
+ ui.item.css( 'background-color','#f6f6f6' );
152
+ },
153
+ stop: function(event,ui){
154
+ ui.item.removeAttr( 'style' );
155
+ },
156
+ update: function(event, ui) {
157
+
158
+ $table = $( this ).closest( 'table' );
159
+ $table.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } });
160
+ // Update fee order
161
+ var data = {
162
+ action: 'wpc_save_post_order',
163
+ form: $( this ).closest( 'form' ).serialize(),
164
+ nonce: wpc.nonce
165
+ };
166
+
167
+ $.post( ajaxurl, data, function( response ) {
168
+ $( '.wpc-conditions-post-table tbody tr:even' ).addClass( 'alternate' );
169
+ $( '.wpc-conditions-post-table tbody tr:odd' ).removeClass( 'alternate' );
170
+ $table.unblock();
171
+ });
172
+ }
173
+ });
174
+
175
+ });
libraries/wp-conditions/assets/js/wp-conditions.min.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(function($){function t(){$(".wpc-conditions").parents(".postbox").repeater({addTrigger:".wpc-condition-group-add",removeTrigger:".wpc-condition-group .delete",template:".wpc-condition-group-template .wpc-condition-group-wrap",elementWrap:".wpc-condition-group-wrap",elementsContainer:".wpc-conditions",removeElement:function(t){t.remove()}})}function o(){$(".wpc-condition-group").repeater({addTrigger:".wpc-condition-add",removeTrigger:".wpc-condition-delete",template:".wpc-condition-template .wpc-condition-wrap",elementWrap:".wpc-condition-wrap",elementsContainer:".wpc-conditions-list"})}t(),o(),jQuery(document.body).on("repeater-added-row",function(t,e,n,i){var a=Math.floor(8999999999*Math.random()+1e9);e.find("input[name], select[name]").attr("name",function(t,o){return o.replace("9999",a)||o}),e.find(".wpc-condition[data-id]").attr("data-id",function(t,o){return o.replace("9999",a)||o}),e.find("[data-group]").attr("data-group",function(t,o){return o.replace("9999",a)||o}),e.find(".repeater-active").removeClass("repeater-active"),o()}),$(document.body).on("click",".wpc-conditions .duplicate",function(){var t=$(this).parents(".wpc-condition-group-wrap"),e=t.find(".wpc-condition-group").attr("data-group"),n=$(this).parents(".wpc-conditions"),i=t.clone(),a=Math.floor(8999999999*Math.random()+1e9);$(t).find("select").each(function(t){$(i).find("select").eq(t).val($(this).val())}),i.find(".wpc-condition-group").attr("data-group",a),i.find("input[name], select[name]").attr("name",function(t,o){return o.replace("conditions["+e+"]","conditions["+a+"]")}),i.find(".repeater-active").removeClass("repeater-active"),n.append(i),o(),$("html, body").on("scroll mousedown DOMMouseScroll mousewheel keydown touchmove",function(t){$("html, body").stop().off("scroll mousedown DOMMouseScroll mousewheel keydown touchmove")}),$("body, html").animate({scrollTop:$(i).offset().top-50},750,function(){$("html, body").off("scroll mousedown DOMMouseScroll mousewheel keydown touchmove")})}),$(document.body).on("change",".wpc-condition",function(){var t='<span style="width: calc( 42.5% - 75px ); border: 1px solid transparent; display: inline-block;">&nbsp;</span>',o={action:wpc2.action_prefix+"update_condition_value",id:$(this).attr("data-id"),group:$(this).parents(".wpc-condition-group").attr("data-group"),condition:$(this).val(),nonce:wpc.nonce},e=$(this).parents(".wpc-condition-wrap").first(),n=".wpc-value-field-wrap";e.find(n).html(t).block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,o,function(t){e.find(n).replaceWith(t),$(document.body).trigger("wc-enhanced-select-init")});var i=e.find(".wpc-operator").val();e.find(".wpc-operator").empty().html(function(){var t=$(this),e=wpc.condition_operators[o.condition]||wpc.condition_operators["default"];$.each(e,function(o,e){t.append($("<option/>").attr("value",o).text(e)),t.val(i).val()||t.val(t.find("option:first").val())})}),e.find(".wpc-description").html(function(){return $('<span class="woocommerce-help-tip" />').attr("data-tip",wpc.condition_descriptions[o.condition]||"")}),$(".tips, .help_tip, .woocommerce-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}),$("#tiptip_holder").removeAttr("style"),$("#tiptip_arrow").removeAttr("style")}),$(".wpc-conditions-post-table.wpc-sortable-post-table tbody").sortable({items:"tr",handle:".sort",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(t,o){o.item.css("background-color","#f6f6f6")},stop:function(t,o){o.item.removeAttr("style")},update:function(t,o){$table=$(this).closest("table"),$table.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e={action:"wpc_save_post_order",form:$(this).closest("form").serialize(),nonce:wpc.nonce};$.post(ajaxurl,e,function(t){$(".wpc-conditions-post-table tbody tr:even").addClass("alternate"),$(".wpc-conditions-post-table tbody tr:odd").removeClass("alternate"),$table.unblock()})}})});
libraries/wp-conditions/conditions/wpc-category-condition.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Category_Condition' ) ) {
5
+
6
+ class WPC_Category_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Category', 'wpc-conditions' );
10
+ $this->slug = __( 'category', 'wpc-conditions' );
11
+ $this->group = __( 'Product', 'wpc-conditions' );
12
+ $this->description = __( 'All products in cart must match the given category', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $value = $this->get_value( $value );
20
+ $match = true;
21
+
22
+ if ( '==' == $operator ) :
23
+
24
+ foreach ( WC()->cart->get_cart() as $product ) :
25
+
26
+ if ( ! has_term( $value, 'product_cat', $product['product_id'] ) ) :
27
+ $match = false;
28
+ endif;
29
+
30
+ endforeach;
31
+
32
+ elseif ( '!=' == $operator ) :
33
+
34
+ foreach ( WC()->cart->get_cart() as $product ) :
35
+
36
+ if ( has_term( $value, 'product_cat', $product['product_id'] ) ) :
37
+ $match = false;
38
+ endif;
39
+
40
+ endforeach;
41
+
42
+ endif;
43
+
44
+ return $match;
45
+
46
+ }
47
+
48
+ public function get_available_operators() {
49
+
50
+ $operators = parent::get_available_operators();
51
+
52
+ unset( $operators['>='] );
53
+ unset( $operators['<='] );
54
+
55
+ return $operators;
56
+
57
+ }
58
+
59
+ public function get_value_field_args() {
60
+
61
+ $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
62
+ $field_args = array(
63
+ 'type' => 'select',
64
+ 'class' => array( 'wpc-value', 'wc-enhanced-select' ),
65
+ 'options' => wp_list_pluck( $categories, 'name', 'slug' ),
66
+ );
67
+
68
+ return $field_args;
69
+
70
+ }
71
+
72
+ }
73
+
74
+ }
libraries/wp-conditions/conditions/wpc-city-condition.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_City_Condition' ) ) {
5
+
6
+ class WPC_City_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'City', 'wpc-conditions' );
10
+ $this->slug = __( 'city', 'wpc-conditions' );
11
+ $this->group = __( 'User', 'wpc-conditions' );
12
+ $this->description = __( 'Compare against customer city. Comma separated list allowed', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ // @todo - Check if this can be cleaned up
18
+ public function match( $match, $operator, $value ) {
19
+
20
+ $value = $this->get_value( $value );
21
+ $customer_city = $this->get_compare_value();
22
+
23
+ if ( '==' == $operator ) :
24
+
25
+ if ( preg_match( '/\, ?/', $value ) ) :
26
+ $match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
27
+ else :
28
+ $match = ( $value == $customer_city );
29
+ endif;
30
+
31
+ elseif ( '!=' == $operator ) :
32
+
33
+ if ( preg_match( '/\, ?/', $value ) ) :
34
+ $match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
35
+ else :
36
+ $match = ( $value == $customer_city );
37
+ endif;
38
+
39
+ endif;
40
+
41
+ return $match;
42
+
43
+ }
44
+
45
+ public function get_value( $value ) {
46
+ return strtolower( $value );
47
+ }
48
+
49
+ public function get_compare_value() {
50
+ return strtolower( WC()->customer->get_shipping_city() );
51
+ }
52
+
53
+ public function get_available_operators() {
54
+
55
+ $operators = parent::get_available_operators();
56
+
57
+ unset( $operators['>='] );
58
+ unset( $operators['<='] );
59
+
60
+ return $operators;
61
+
62
+ }
63
+
64
+ }
65
+
66
+ }
libraries/wp-conditions/conditions/wpc-condition.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Condition' ) ) {
5
+
6
+ abstract class WPC_Condition {
7
+
8
+ protected $name = null;
9
+ protected $slug = null;
10
+ protected $group = null;
11
+ protected $description = null;
12
+ protected $value_field_args = array();
13
+ protected $available_operators = array();
14
+
15
+ /**
16
+ * Constructor.
17
+ *
18
+ * @since 1.0.0
19
+ */
20
+ public function __construct() {
21
+ if ( is_null( $this->get_slug() ) ) {
22
+ $this->slug = sanitize_key( $this->get_name() );
23
+ }
24
+ }
25
+
26
+ public function get_name() {
27
+ return $this->name;
28
+ }
29
+
30
+ public function get_slug() {
31
+ return $this->slug;
32
+ }
33
+
34
+ public function get_group() {
35
+ return $this->group;
36
+ }
37
+
38
+ /**
39
+ * @return array
40
+ */
41
+ public function get_available_operators() {
42
+
43
+ if ( empty( $this->available_operators ) ) {
44
+ $this->available_operators = array(
45
+ '==' => __( 'Equal to', 'wpc-conditions' ),
46
+ '!=' => __( 'Not equal to', 'wpc-conditions' ),
47
+ '>=' => __( 'Greater or equal to', 'wpc-conditions' ),
48
+ '<=' => __( 'Less or equal to ', 'wpc-conditions' ),
49
+ );
50
+ }
51
+
52
+ return $this->available_operators;
53
+
54
+ }
55
+
56
+ public function get_value_field_args() {
57
+
58
+ if ( empty( $this->value_field_args ) ) {
59
+ $this->value_field_args = array(
60
+ 'type' => 'text',
61
+ 'class' => array( 'wpc-value' ),
62
+ 'placeholder' => '',
63
+ );
64
+ }
65
+
66
+ return $this->value_field_args;
67
+
68
+ }
69
+
70
+ /**
71
+ * Get condition value.
72
+ *
73
+ * Get the value the store owner has set.
74
+ *
75
+ * @since 1.0.0
76
+ *
77
+ * @param $value
78
+ * @return string
79
+ */
80
+ public function get_value( $value ) {
81
+ return $value;
82
+ }
83
+
84
+ /**
85
+ * Get the compare value.
86
+ *
87
+ * Get the value the main value should compare against.
88
+ *
89
+ * @since 1.0.0
90
+ *
91
+ * @return string|mixed The value to compare the store-owner set value against.
92
+ */
93
+ public function get_compare_value() {
94
+
95
+ $compare_value = '';
96
+ return $compare_value;
97
+ }
98
+
99
+ public function match( $match, $operator, $value ) {
100
+
101
+ $value = $this->get_value( $value );
102
+ $compare_value = $this->get_compare_value();
103
+
104
+ if ( '==' == $operator ) :
105
+ $match = ( $compare_value == $value );
106
+ elseif ( '!=' == $operator ) :
107
+ $match = ( $compare_value != $value );
108
+ elseif ( '>=' == $operator ) :
109
+ $match = ( $compare_value >= $value );
110
+ elseif ( '<=' == $operator ) :
111
+ $match = ( $compare_value <= $value );
112
+ endif;
113
+
114
+ return $match;
115
+ }
116
+
117
+ public function get_description() {
118
+ return $this->description;
119
+ }
120
+
121
+ }
122
+
123
+ }
libraries/wp-conditions/conditions/wpc-contains-category-condition.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Contains_Category_Condition' ) ) {
5
+
6
+ class WPC_Contains_Category_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Contains Category', 'wpc-conditions' );
10
+ $this->slug = __( 'contains_category', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Cart must contain at least one product with the selected category', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $value = $this->get_value( $value );
20
+
21
+ if ( '==' == $operator ) :
22
+
23
+ foreach ( WC()->cart->get_cart() as $product ) :
24
+
25
+ if ( has_term( $value, 'product_cat', $product['product_id'] ) ) :
26
+ return true;
27
+ endif;
28
+
29
+ endforeach;
30
+
31
+ elseif ( '!=' == $operator ) :
32
+
33
+ $match = true;
34
+ foreach ( WC()->cart->get_cart() as $product ) :
35
+
36
+ if ( has_term( $value, 'product_cat', $product['product_id'] ) ) :
37
+ return false;
38
+ endif;
39
+
40
+ endforeach;
41
+
42
+ endif;
43
+
44
+ return $match;
45
+
46
+ }
47
+
48
+ public function get_available_operators() {
49
+
50
+ $operators = parent::get_available_operators();
51
+
52
+ unset( $operators['>='] );
53
+ unset( $operators['<='] );
54
+
55
+ return $operators;
56
+
57
+ }
58
+
59
+ public function get_value_field_args() {
60
+
61
+ $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
62
+ $field_args = array(
63
+ 'type' => 'select',
64
+ 'class' => array( 'wpc-value', 'wc-enhanced-select' ),
65
+ 'options' => wp_list_pluck( $categories, 'name', 'slug' ),
66
+ );
67
+
68
+ return $field_args;
69
+
70
+ }
71
+
72
+ }
73
+
74
+ }
libraries/wp-conditions/conditions/wpc-contains-product-condition.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Contains_Product_Condition' ) ) {
5
+
6
+ class WPC_Contains_Product_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Contains product', 'wpc-conditions' );
10
+ $this->slug = __( 'contains_product', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Check if a product is or is not present in the cart', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $product_ids = $this->get_compare_value();
20
+
21
+ if ( '==' == $operator ) :
22
+ $match = ( in_array( $value, $product_ids ) );
23
+ elseif ( '!=' == $operator ) :
24
+ $match = ( ! in_array( $value, $product_ids ) );
25
+ endif;
26
+
27
+ return $match;
28
+
29
+ }
30
+
31
+ public function get_compare_value() {
32
+
33
+ $product_ids = array();
34
+ foreach ( WC()->cart->cart_contents as $product ) :
35
+ $product_ids[] = $product['product_id'];
36
+ if ( isset( $product['variation_id'] ) ) {
37
+ $product_ids[] = $product['variation_id'];
38
+ }
39
+ endforeach;
40
+
41
+ return $product_ids;
42
+
43
+ }
44
+
45
+ public function get_available_operators() {
46
+
47
+ $operators = parent::get_available_operators();
48
+
49
+ unset( $operators['>='] );
50
+ unset( $operators['<='] );
51
+
52
+ return $operators;
53
+
54
+ }
55
+
56
+ // @todo
57
+ public function get_value_field_args() {
58
+
59
+ $field_args = array(
60
+ 'type' => 'text',
61
+ 'custom_attributes' => array(
62
+ 'data-placeholder' => __( 'Search for a product', 'wp-conditions' ),
63
+ ),
64
+ 'class' => array( 'wpc-value', 'wc-product-search' ),
65
+ 'options' => array(),
66
+ );
67
+
68
+ if ( version_compare( WC()->version, '2.7', '>=' ) ) {
69
+ $field_args['type'] = 'select';
70
+ }
71
+
72
+ return $field_args;
73
+
74
+ }
75
+
76
+ }
77
+
78
+ }
libraries/wp-conditions/conditions/wpc-contains-shipping-class-condition.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Contains_Shipping_Class_Condition' ) ) {
5
+
6
+ class WPC_Contains_Shipping_Class_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Contains shipping class', 'wpc-conditions' );
10
+ $this->slug = __( 'contains_shipping_class', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Check if a shipping class is or is not present in the cart', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ foreach ( WC()->cart->get_cart() as $product ) {
20
+
21
+ $id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
22
+ $product = wc_get_product( $id );
23
+
24
+ if ( $operator == '==' ) {
25
+ if ( $product->get_shipping_class() == $value ) {
26
+ return true;
27
+ }
28
+ } elseif ( $operator == '!=' ) {
29
+ $match = true;
30
+ if ( $product->get_shipping_class() == $value ) {
31
+ return false;
32
+ }
33
+ }
34
+
35
+ }
36
+
37
+ return $match;
38
+
39
+ }
40
+
41
+ public function get_available_operators() {
42
+
43
+ $operators = parent::get_available_operators();
44
+
45
+ unset( $operators['>='] );
46
+ unset( $operators['<='] );
47
+
48
+ return $operators;
49
+
50
+ }
51
+
52
+ public function get_value_field_args() {
53
+
54
+ $shipping_classes = get_terms( 'product_shipping_class', array( 'hide_empty' => false ) );
55
+ $shipping_classes = array_merge(
56
+ array( '-1' => __( 'No shipping class', 'woocommerce' ) ),
57
+ wp_list_pluck( $shipping_classes, 'name', 'slug' )
58
+ );
59
+
60
+ $field_args = array(
61
+ 'type' => 'select',
62
+ 'options' => $shipping_classes,
63
+ 'class' => array( 'wpc-value', 'wc-enhanced-select' ),
64
+ );
65
+
66
+ return $field_args;
67
+
68
+ }
69
+
70
+ }
71
+
72
+ }
libraries/wp-conditions/conditions/wpc-country-condition.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Country_Condition' ) ) {
5
+
6
+ class WPC_Country_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Country', 'wpc-conditions' );
10
+ $this->slug = __( 'country', 'wpc-conditions' );
11
+ $this->group = __( 'User', 'wpc-conditions' );
12
+ $this->description = __( 'Compare against the customer country', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $value = $this->get_value( $value );
20
+ $customer_country = $this->get_compare_value();
21
+
22
+ if ( method_exists( WC()->countries, 'get_continent_code_for_country' ) ) :
23
+ $customer_continent = WC()->countries->get_continent_code_for_country( $customer_country );
24
+ endif;
25
+
26
+ if ( '==' == $operator ) :
27
+ $match = stripos( $customer_country, $value ) === 0;
28
+
29
+ // Check for continents if available
30
+ if ( ! $match && isset( $customer_continent ) && strpos( $value, 'CO_' ) === 0 ) :
31
+ $match = stripos( $customer_continent, str_replace( 'CO_','', $value ) ) === 0;
32
+ endif;
33
+ elseif ( '!=' == $operator ) :
34
+ $match = stripos( $customer_country, $value ) === false;
35
+
36
+ // Check for continents if available
37
+ if ( ! $match && isset( $customer_continent ) && strpos( $value, 'CO_' ) === 0 ) :
38
+ $match = stripos( $customer_continent, str_replace( 'CO_','', $value ) ) === false;
39
+ endif;
40
+ endif;
41
+
42
+ return $match;
43
+
44
+ }
45
+
46
+ public function get_compare_value() {
47
+ return WC()->customer->get_shipping_country();
48
+ }
49
+
50
+ public function get_available_operators() {
51
+
52
+ $operators = parent::get_available_operators();
53
+
54
+ unset( $operators['>='] );
55
+ unset( $operators['<='] );
56
+
57
+ return $operators;
58
+
59
+ }
60
+
61
+ // @todo test with <2.5 to see how 'Continents' react
62
+ public function get_value_field_args() {
63
+
64
+ $countries = WC()->countries->get_allowed_countries() + WC()->countries->get_shipping_countries();
65
+ $continents = array();
66
+ if ( method_exists( WC()->countries, 'get_continents' ) ) :
67
+ foreach ( WC()->countries->get_continents() as $k => $v ) :
68
+ $continents[ 'CO_' . $k ] = $v['name']; // Add prefix for country key compatibility
69
+ endforeach;
70
+ endif;
71
+
72
+ $field_args = array(
73
+ 'type' => 'select',
74
+ 'class' => array( 'wpc-value', 'wc-enhanced-select' ),
75
+ 'options' => array(
76
+ __( 'Continents', 'woocommerce' ) => $continents,
77
+ __( 'Countries', 'woocommerce' ) => $countries,
78
+ ),
79
+ );
80
+
81
+ return $field_args;
82
+
83
+ }
84
+
85
+ }
86
+
87
+ }
libraries/wp-conditions/conditions/wpc-coupon-condition.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Coupon_Condition' ) ) {
5
+
6
+ class WPC_Coupon_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Coupon', 'wpc-conditions' );
10
+ $this->slug = __( 'coupon', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Matched against the applied coupon codes or coupon amounts (use \'%\' or \'$\' for the respective amounts', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $value = $this->get_value( $value );
20
+ $coupons = $this->get_compare_value();
21
+
22
+ // Match against coupon percentage
23
+ if ( strpos( $value, '%' ) !== false ) {
24
+ $percentage_value = str_replace( '%', '', $value );
25
+ if ( '==' == $operator ) :
26
+ $match = in_array( $percentage_value, $coupons['percent'] );
27
+ elseif ( '!=' == $operator ) :
28
+ $match = ! in_array( $percentage_value, $coupons['percent'] );
29
+ elseif ( '>=' == $operator ) :
30
+ $match = empty( $coupons['percent'] ) ? $match : ( min( $coupons['percent'] ) >= $percentage_value );
31
+ elseif ( '<=' == $operator ) :
32
+ $match = ! is_array( $coupons['percent'] ) ? false : ( max( $coupons['percent'] ) <= $percentage_value );
33
+ endif;
34
+
35
+ // Match against coupon amount
36
+ } elseif( strpos( $value, '$' ) !== false ) {
37
+ $amount_value = str_replace( '$', '', $value );
38
+ if ( '==' == $operator ) :
39
+ $match = in_array( $amount_value, $coupons['fixed'] );
40
+ elseif ( '!=' == $operator ) :
41
+ $match = ! in_array( $amount_value, $coupons['fixed'] );
42
+ elseif ( '>=' == $operator ) :
43
+ $match = empty( $coupons['fixed'] ) ? $match : ( min( $coupons['fixed'] ) >= $amount_value );
44
+ elseif ( '<=' == $operator ) :
45
+ $match = ! is_array( $coupons['fixed'] ) ? $match : ( max( $coupons['fixed'] ) <= $amount_value );
46
+ endif;
47
+
48
+ // Match coupon codes
49
+ } else {
50
+ if ( '==' == $operator ) :
51
+ $match = ( array_intersect( preg_split( '/\, ?/', $value ), WC()->cart->get_applied_coupons() ) );
52
+ elseif ( '!=' == $operator ) :
53
+ $match = ( ! array_intersect( preg_split( '/\, ?/', $value ), WC()->cart->get_applied_coupons() ) );
54
+ endif;
55
+ }
56
+
57
+ return $match;
58
+
59
+ }
60
+
61
+ public function get_compare_value() {
62
+
63
+ $coupons = array( 'percent' => array(), 'fixed' => array() );
64
+ foreach ( WC()->cart->get_coupons() as $coupon ) {
65
+ $type = str_replace( '_product', '', $coupon->discount_type );
66
+ $type = str_replace( '_cart', '', $type );
67
+ $coupons[ $type ][] = $coupon->coupon_amount;
68
+ }
69
+
70
+ return $coupons;
71
+
72
+ }
73
+
74
+ }
75
+
76
+ }
libraries/wp-conditions/conditions/wpc-date-condition.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Date_Condition' ) ) {
5
+
6
+ class WPC_Date_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Date', 'wpc-conditions' );
10
+ $this->slug = __( 'date', 'wpc-conditions' );
11
+ $this->group = __( 'General', 'wpc-conditions' );
12
+ $this->description = sprintf( __( 'Compares given date to the current date. Current date: %s', 'wpc-conditions' ), date_i18n( get_option( 'date_format' ) ) );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_value( $value ) {
18
+ return date( 'Y-m-d', strtotime( $value ) ); // Set date in Year-Month-Day format
19
+ }
20
+
21
+ public function get_compare_value() {
22
+ return current_time( 'Y-m-d' ); // Today's date in Year-Month-Day format
23
+ }
24
+
25
+ public function get_value_field_args() {
26
+
27
+ $field_args = array(
28
+ 'type' => 'text',
29
+ 'class' => array( 'wpc-value' ),
30
+ 'placeholder' => 'dd-mm-yyyy or yyyy-mm-dd',
31
+ );
32
+
33
+ return $field_args;
34
+
35
+ }
36
+
37
+ }
38
+
39
+ }
libraries/wp-conditions/conditions/wpc-day-condition.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Day_Condition' ) ) {
5
+
6
+ class WPC_Day_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Day', 'wpc-conditions' );
10
+ $this->slug = __( 'day', 'wpc-conditions' );
11
+ $this->group = __( 'General', 'wpc-conditions' );
12
+ $this->description = sprintf( __( 'Compare to day. You can use ranges with greater/less operators. Current day: %s', 'wpc-conditions' ), date_i18n( 'l' ) );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_compare_value() {
18
+ return current_time( 'N' ); // Returns current day
19
+ }
20
+
21
+ public function get_value_field_args() {
22
+
23
+ $days[1] = 'Monday';
24
+ $days[2] = 'Tuesday';
25
+ $days[3] = 'Wednesday';
26
+ $days[4] = 'Thursday';
27
+ $days[5] = 'Friday';
28
+ $days[6] = 'Saturday';
29
+ $days[7] = 'Sunday';
30
+
31
+ $field_args = array(
32
+ 'type' => 'select',
33
+ 'class' => array( 'wpc-value' ),
34
+ 'options' => $days,
35
+ );
36
+
37
+ return $field_args;
38
+
39
+ }
40
+
41
+ }
42
+
43
+ }
libraries/wp-conditions/conditions/wpc-fallback-condition.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Fallback_Condition' ) ) {
5
+
6
+
7
+ /**
8
+ * Fallback condition is used when wpc_get_condition() is used for a
9
+ * invalid (unknown) condition class. This ensures nothing breaks and
10
+ * the initial $match value is returned > ready to be handled by the filter hook.
11
+ */
12
+ class WPC_Fallback_Condition extends WPC_Condition {
13
+
14
+ public function __construct() {
15
+ $this->name = __( '', 'wpc-conditions' );
16
+ $this->slug = __( '', 'wpc-conditions' );
17
+ $this->description = __( '', 'wpc-conditions' );
18
+
19
+ parent::__construct();
20
+ }
21
+
22
+ public function match( $match, $operator, $value ) {
23
+ return $match;
24
+ }
25
+
26
+ }
27
+
28
+ }
libraries/wp-conditions/conditions/wpc-height-condition.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Height_Condition' ) ) {
5
+
6
+ class WPC_Height_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Height', 'wpc-conditions' );
10
+ $this->slug = __( 'height', 'wpc-conditions' );
11
+ $this->group = __( 'Product', 'wpc-conditions' );
12
+ $this->description = __( 'Compared to highest product in cart', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_compare_value() {
18
+
19
+ $height = array();
20
+ foreach ( WC()->cart->get_cart() as $product ) :
21
+
22
+ if ( true == $product['data']->variation_has_height ) :
23
+ $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) );
24
+ else :
25
+ $height[] = ( get_post_meta( $product['product_id'], '_height', true ) );
26
+ endif;
27
+
28
+ endforeach;
29
+
30
+ return max( $height );
31
+
32
+ }
33
+
34
+ }
35
+
36
+ }
libraries/wp-conditions/conditions/wpc-length-condition.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Length_Condition' ) ) {
5
+
6
+ class WPC_Length_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Length', 'wpc-conditions' );
10
+ $this->slug = __( 'length', 'wpc-conditions' );
11
+ $this->group = __( 'Product', 'wpc-conditions' );
12
+ $this->description = __( 'Compared to lengthiest product in cart', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_compare_value() {
18
+
19
+ $length = array();
20
+ foreach ( WC()->cart->get_cart() as $product ) :
21
+
22
+ if ( true == $product['data']->variation_has_length ) :
23
+ $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) );
24
+ else :
25
+ $length[] = ( get_post_meta( $product['product_id'], '_length', true ) );
26
+ endif;
27
+
28
+ endforeach;
29
+
30
+ return max( $length );
31
+
32
+ }
33
+
34
+ }
35
+
36
+ }
libraries/wp-conditions/conditions/wpc-page-condition.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Page_Condition' ) ) {
5
+
6
+ class WPC_Page_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Page', 'wpc-conditions' );
10
+ $this->slug = __( 'page', 'wpc-conditions' );
11
+ $this->group = __( 'General', 'wpc-conditions' );
12
+ $this->description = __( 'Match the given page to the viewing page', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ global $post;
20
+
21
+ $value = $this->get_value( $value );
22
+ $wp_query = $this->get_compare_value();
23
+
24
+ if ( '==' == $operator ) :
25
+
26
+ if ( is_array( term_exists ( $value, 'product_cat' ) ) ) : // term_exists return array when true
27
+ $match = ( $wp_query->is_archive() && isset( $wp_query->query_vars['product_cat'] ) && $value == $wp_query->query_vars['product_cat'] );
28
+ elseif ( wc_get_page_id( 'shop' ) == $value ) : // Shop page
29
+ $match = ( 'product' == $wp_query->query_vars['post_type'] && $wp_query->is_archive() );
30
+ else :
31
+ $match = ( $post->ID == $value );
32
+ endif;
33
+
34
+ elseif ( '!=' == $operator ) :
35
+
36
+ if ( is_array( term_exists ( $value, 'product_cat' ) ) ) : // term_exists return array when true
37
+ $match = ( $wp_query->is_archive() && isset( $wp_query->query_vars['product_cat'] ) && $value != $wp_query->query_vars['product_cat'] );
38
+ elseif ( wc_get_page_id( 'shop' ) == $value ) : // Shop page
39
+ $match = ! ( 'product' == $wp_query->query_vars['post_type'] && $wp_query->is_archive() );
40
+ else :
41
+ $match = ( $post->ID != $value );
42
+ endif;
43
+
44
+ endif;
45
+
46
+ return $match;
47
+
48
+ }
49
+
50
+ public function get_compare_value() {
51
+ global $wp_query;
52
+ return $wp_query;
53
+ }
54
+
55
+ public function get_available_operators() {
56
+
57
+ $operators = parent::get_available_operators();
58
+
59
+ unset( $operators['>='] );
60
+ unset( $operators['<='] );
61
+
62
+ return $operators;
63
+
64
+ }
65
+
66
+ public function get_value_field_args() {
67
+
68
+ $wc_pages = array(
69
+ get_option( 'woocommerce_shop_page_id' ) => __( 'Shop page', 'woocommerce-advanced-messages' ),
70
+ get_option( 'woocommerce_cart_page_id' ) => __( 'Cart', 'woocommerce-advanced-messages' ),
71
+ get_option( 'woocommerce_checkout_page_id' ) => __( 'Checkout', 'woocommerce-advanced-messages' ),
72
+ get_option( 'woocommerce_terms_page_id' ) => __( 'Terms & conditions', 'woocommerce-advanced-messages' ),
73
+ get_option( 'woocommerce_myaccount_page_id' ) => __( 'My account', 'woocommerce-advanced-messages' ),
74
+ );
75
+ $wc_categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
76
+ $wc_categories = wp_list_pluck( $wc_categories, 'name', 'slug' );
77
+
78
+ $wc_products = array();
79
+ $products = get_posts( array( 'posts_per_page' => 9999, 'post_type' => 'product', 'order' => 'asc', 'orderby' => 'title' ) );
80
+ foreach ( $products as $product ) :
81
+ $wc_products[ $product->ID ] = $product->post_title;
82
+ endforeach;
83
+
84
+ $field_args = array(
85
+ 'type' => 'select',
86
+ 'class' => array( 'wpc-value', 'wc-enhanced-select' ),
87
+ 'options' => array(
88
+ 'WooCommerce pages' => $wc_pages,
89
+ 'Product categories' => $wc_categories,
90
+ 'Products' => $wc_products,
91
+ ),
92
+ );
93
+
94
+ return $field_args;
95
+
96
+ }
97
+
98
+ }
99
+
100
+ }
libraries/wp-conditions/conditions/wpc-payment-gateway-condition.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Payment_Gateway_Condition' ) ) {
5
+
6
+ class WPC_Payment_Gateway_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Payment Gateway', 'wpc-conditions' );
10
+ $this->slug = __( 'payment_gateway', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Payment gateway can only be checked in the checkout', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_compare_value() {
18
+ return WC()->session->get( 'chosen_payment_method' );
19
+ }
20
+
21
+ public function get_available_operators() {
22
+
23
+ $operators = parent::get_available_operators();
24
+
25
+ unset( $operators['>='] );
26
+ unset( $operators['<='] );
27
+
28
+ return $operators;
29
+
30
+ }
31
+
32
+ public function get_value_field_args() {
33
+
34
+ $field_args = array(
35
+ 'type' => 'select',
36
+ );
37
+
38
+ foreach ( WC()->payment_gateways->payment_gateways() as $gateway ) :
39
+ $field_args['options'][ $gateway->id ] = $gateway->get_title();
40
+ endforeach;
41
+
42
+ return $field_args;
43
+
44
+ }
45
+
46
+ }
47
+
48
+ }
libraries/wp-conditions/conditions/wpc-quantity-condition.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Quantity_Condition' ) ) {
5
+
6
+ class WPC_Quantity_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Quantity', 'wpc-conditions' );
10
+ $this->slug = __( 'quantity', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Compared against the quantity of items in the cart', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_compare_value() {
18
+ return WC()->cart->get_cart_contents_count();
19
+ }
20
+
21
+ public function get_value_field_args() {
22
+
23
+ $field_args = array(
24
+ 'type' => 'number',
25
+ );
26
+
27
+ return $field_args;
28
+
29
+ }
30
+
31
+ }
32
+
33
+ }
libraries/wp-conditions/conditions/wpc-role-condition.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Role_Condition' ) ) {
5
+
6
+ class WPC_Role_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Role', 'wpc-conditions' );
10
+ $this->slug = __( 'role', 'wpc-conditions' );
11
+ $this->group = __( 'User', 'wpc-conditions' );
12
+ $this->description = __( 'Compare against the user role', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $value = $this->get_value( $value );
20
+ $user_caps = $this->get_compare_value();
21
+
22
+ if ( '==' == $operator ) :
23
+ $match = ( array_key_exists( $value, $user_caps ) );
24
+ elseif ( '!=' == $operator ) :
25
+ $match = ( ! array_key_exists( $value, $user_caps ) );
26
+ endif;
27
+
28
+ return $match;
29
+
30
+ }
31
+
32
+ public function get_compare_value() {
33
+ global $current_user;
34
+ return $current_user->caps;
35
+ }
36
+
37
+ public function get_available_operators() {
38
+
39
+ $operators = parent::get_available_operators();
40
+
41
+ unset( $operators['>='] );
42
+ unset( $operators['<='] );
43
+
44
+ return $operators;
45
+
46
+ }
47
+
48
+ public function get_value_field_args() {
49
+
50
+ $user_roles = array_keys( get_editable_roles() );
51
+
52
+ $field_args = array(
53
+ 'type' => 'select',
54
+ 'class' => array( 'wpc-value' ),
55
+ 'options' => array_combine( $user_roles, $user_roles ),
56
+ );
57
+
58
+ return $field_args;
59
+
60
+ }
61
+
62
+ }
63
+
64
+ }
libraries/wp-conditions/conditions/wpc-shipping-method-condition.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Shipping_Method_Condition' ) ) {
5
+
6
+ class WPC_Shipping_Method_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Shipping method', 'wpc-conditions' );
10
+ $this->slug = __( 'shipping_method', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Match against the chosen shipping method', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $value = $this->get_value( $value );
20
+ $chosen_shipping_methods = $this->get_compare_value();
21
+
22
+ if ( '==' == $operator ) :
23
+ $match = ( in_array( $value, $chosen_shipping_methods ) );
24
+ elseif ( '!=' == $operator ) :
25
+ $match = ( ! in_array( $value, $chosen_shipping_methods ) );
26
+ endif;
27
+
28
+ return $match;
29
+
30
+ }
31
+
32
+ public function get_compare_value() {
33
+ return (array) WC()->session->get( 'chosen_shipping_methods' );
34
+ }
35
+
36
+ public function get_available_operators() {
37
+
38
+ $operators = parent::get_available_operators();
39
+
40
+ unset( $operators['>='] );
41
+ unset( $operators['<='] );
42
+
43
+ return $operators;
44
+
45
+ }
46
+
47
+ public function get_value_field_args() {
48
+
49
+ $field_args = array(
50
+ 'type' => 'select',
51
+ 'options' => $this->get_shipping_options(),
52
+ );
53
+
54
+ return $field_args;
55
+
56
+ }
57
+
58
+ private function get_shipping_options() {
59
+
60
+ $shipping_options = array();
61
+ foreach ( WC()->shipping->load_shipping_methods() as $method ) :
62
+ $shipping_options['Methods'][ $method->id ] = $method->get_title();
63
+ endforeach;
64
+
65
+ // Advanced Shipping
66
+ $shipping_options = array_merge( $shipping_options, $this->get_advanced_shipping_rates() );
67
+
68
+ // WC Zones
69
+ $shipping_options = array_merge( $shipping_options, $this->get_zone_instances() );
70
+
71
+ return $shipping_options;
72
+
73
+ }
74
+
75
+
76
+ /**
77
+ * Get Advanced Shipping rates.
78
+ *
79
+ * Get the rates from the Advanced Shipping plugin (if available).
80
+ *
81
+ * @link https://codecanyon.net/item/woocommerce-advanced-shipping/8634573
82
+ *
83
+ * @return array List of shipping rates.
84
+ */
85
+ private function get_advanced_shipping_rates() {
86
+
87
+ $rates = array();
88
+
89
+ $was_rates = new WP_Query( array( 'fields' => 'ids', 'post_type' => 'was', 'post_status' => 'any', 'posts_per_page' => 1000, 'update_post_term_cache' => false, 'no_found_rows' => true ) );
90
+ $was_rates = $was_rates->get_posts();
91
+ foreach ( $was_rates as $was_id ) :
92
+ $shipping_method = get_post_meta( $was_id, '_was_shipping_method', true );
93
+ $rates['Advanced Shipping'][ $was_id ] = isset( $shipping_method['shipping_title'] ) ? $shipping_method['shipping_title'] : 'WooCommerce Advanced Shipping rate ID ' . $was_id;
94
+ endforeach;
95
+
96
+ return $rates;
97
+
98
+ }
99
+
100
+
101
+ /**
102
+ * Get zone instances.
103
+ *
104
+ * Get the rates that are within a shipping zone.
105
+ *
106
+ * @return array List of shipping rates.
107
+ */
108
+ private function get_zone_instances() {
109
+
110
+ $rates = array();
111
+
112
+ if ( ! class_exists( 'WC_Shipping_Zones' ) ) {
113
+ return $rates;
114
+ }
115
+
116
+ foreach ( WC_Shipping_Zones::get_zones() as $zone ) {
117
+ foreach ( $zone['shipping_methods'] as $instance_id => $rate ) {
118
+ $rates[ $zone['zone_name'] ][ $rate->get_rate_id() ] = $rate->get_title();
119
+ }
120
+ }
121
+
122
+ // 'Rest of the world' zone
123
+ $row_zone = WC_Shipping_Zones::get_zone( 0 );
124
+ foreach ( $row_zone->get_shipping_methods() as $instance_id => $rate ) {
125
+ $rates[ $row_zone->get_zone_name() ][ $rate->get_rate_id() ] = $rate->get_title();
126
+ }
127
+
128
+ return $rates;
129
+
130
+ }
131
+
132
+ }
133
+
134
+ }
libraries/wp-conditions/conditions/wpc-state-condition.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_State_Condition' ) ) {
5
+
6
+ class WPC_State_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'State', 'wpc-conditions' );
10
+ $this->slug = __( 'state', 'wpc-conditions' );
11
+ $this->group = __( 'User', 'wpc-conditions' );
12
+ $this->description = __( 'Compare against the customer state. Note: only installed states will show up', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_compare_value() {
18
+ return WC()->customer->get_shipping_country() . '_' . WC()->customer->get_shipping_state();
19
+ }
20
+
21
+ public function get_available_operators() {
22
+
23
+ $operators = parent::get_available_operators();
24
+
25
+ unset( $operators['>='] );
26
+ unset( $operators['<='] );
27
+
28
+ return $operators;
29
+
30
+ }
31
+
32
+ public function get_value_field_args() {
33
+
34
+
35
+ $country_states = array();
36
+ foreach ( WC()->countries->states as $country => $states ) {
37
+
38
+ if ( empty( $states ) ) continue; // Don't show country if it has no states
39
+ if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries
40
+
41
+ foreach ( $states as $state_key => $state ) {
42
+ $country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state;
43
+ }
44
+
45
+ }
46
+
47
+ $field_args = array(
48
+ 'type' => 'select',
49
+ 'class' => array( 'wpc-value', 'wc-enhanced-select' ),
50
+ 'options' => $country_states,
51
+ );
52
+
53
+ return $field_args;
54
+
55
+ }
56
+
57
+ }
58
+
59
+ }
libraries/wp-conditions/conditions/wpc-stock-condition.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Stock_Condition' ) ) {
5
+
6
+ class WPC_Stock_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Stock', 'wpc-conditions' );
10
+ $this->slug = __( 'stock', 'wpc-conditions' );
11
+ $this->group = __( 'Product', 'wpc-conditions' );
12
+ $this->description = __( 'Compared against the product with the lowest stock amount.', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_compare_value() {
18
+
19
+ $stock = array();
20
+
21
+ // $package['contents']
22
+ foreach ( WC()->cart->get_cart() as $product ) :
23
+
24
+ if ( true == $product['data']->variation_has_stock ) :
25
+ $stock[] = ( get_post_meta( $product['data']->variation_id, '_stock', true ) );
26
+ else :
27
+ $stock[] = ( get_post_meta( $product['product_id'], '_stock', true ) );
28
+ endif;
29
+
30
+ endforeach;
31
+
32
+ // Get lowest value
33
+ return min( $stock );
34
+
35
+ }
36
+
37
+ }
38
+
39
+ }
libraries/wp-conditions/conditions/wpc-stock-status-condition.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Stock_Status_Condition' ) ) {
5
+
6
+ class WPC_Stock_Status_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Stock status', 'wpc-conditions' );
10
+ $this->slug = __( 'stock_status', 'wpc-conditions' );
11
+ $this->group = __( 'Product', 'wpc-conditions' );
12
+ $this->description = __( 'All products in cart must match stock status', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $value = $this->get_value( $value );
20
+
21
+ if ( '==' == $operator ) :
22
+
23
+ $match = true;
24
+ // $package['contents']
25
+ foreach ( WC()->cart->get_cart() as $product ) :
26
+
27
+ if ( true == $product['data']->variation_has_stock ) :
28
+ $stock_status = ( get_post_meta( $product['data']->variation_id, '_stock_status', true ) );
29
+ else :
30
+ $stock_status = ( get_post_meta( $product['product_id'], '_stock_status', true ) );
31
+ endif;
32
+
33
+ if ( $stock_status != $value ) :
34
+ $match = false;
35
+ endif;
36
+
37
+ endforeach;
38
+
39
+ elseif ( '!=' == $operator ) :
40
+
41
+ $match = true;
42
+ // $package['contents']
43
+ foreach ( WC()->cart->get_cart() as $product ) :
44
+
45
+ if ( true == $product['data']->variation_has_stock ) :
46
+ $stock_status = ( get_post_meta( $product['data']->variation_id, '_stock_status', true ) );
47
+ else :
48
+ $stock_status = ( get_post_meta( $product['product_id'], '_stock_status', true ) );
49
+ endif;
50
+
51
+ if ( $stock_status == $value ) :
52
+ $match = false;
53
+ endif;
54
+
55
+ endforeach;
56
+
57
+ endif;
58
+
59
+ }
60
+
61
+ public function get_available_operators() {
62
+
63
+ $operators = parent::get_available_operators();
64
+
65
+ unset( $operators['>='] );
66
+ unset( $operators['<='] );
67
+
68
+ return $operators;
69
+
70
+ }
71
+
72
+ }
73
+
74
+ }
libraries/wp-conditions/conditions/wpc-subtotal-condition.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Subtotal_Condition' ) ) {
5
+
6
+ class WPC_Subtotal_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Subtotal', 'wpc-conditions' );
10
+ $this->slug = __( 'subtotal', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Compared against the order subtotal', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_value( $value ) {
18
+ // Make sure its formatted correct
19
+ return str_replace( ',', '.', $value );
20
+ }
21
+
22
+ public function get_compare_value() {
23
+ return WC()->cart->subtotal;
24
+ }
25
+
26
+ }
27
+
28
+ }
libraries/wp-conditions/conditions/wpc-subtotal-ex-tax-condition.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Subtotal_Ex_Tax_Condition' ) ) {
5
+
6
+ class WPC_Subtotal_Ex_Tax_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Subtotal ex. taxes', 'wpc-conditions' );
10
+ $this->slug = __( 'subtotal_ex_tax', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Compared against the order subtotal excluding taxes', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_value( $value ) {
18
+ return str_replace( ',', '.', $value );
19
+ }
20
+
21
+ public function get_compare_value() {
22
+ return WC()->cart->subtotal_ex_tax;
23
+ }
24
+
25
+ }
26
+
27
+ }
libraries/wp-conditions/conditions/wpc-tax-condition.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Tax_Condition' ) ) {
5
+
6
+ class WPC_Tax_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Tax', 'wpc-conditions' );
10
+ $this->slug = __( 'tax', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Compared against the tax total amount', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_value( $value ) {
18
+ return str_replace( ',', '.', $value );
19
+ }
20
+
21
+ public function get_compare_value() {
22
+ return array_sum( (array) WC()->cart->taxes );
23
+ }
24
+
25
+ }
26
+
27
+ }
libraries/wp-conditions/conditions/wpc-time-condition.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Time_Condition' ) ) {
5
+
6
+ class WPC_Time_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Time', 'wpc-conditions' );
10
+ $this->slug = __( 'time', 'wpc-conditions' );
11
+ $this->group = __( 'General', 'wpc-conditions' );
12
+ $this->description = sprintf( __( 'Compares current server time to user given time. Current time: %s', 'woocommerce-advanced-messages' ), date_i18n( get_option( 'time_format' ) ) );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_value( $value ) {
18
+ return date_i18n( 'H:i', strtotime( $value ) ); // Returns set time in Hour:Minutes
19
+ }
20
+
21
+ public function get_compare_value() {
22
+ return current_time( 'H:i' ); // Compares against current time in Hour:Minutes
23
+ }
24
+
25
+ public function get_value_field_args() {
26
+
27
+ $field_args = array(
28
+ 'type' => 'text',
29
+ 'class' => array( 'wpc-value' ),
30
+ 'placeholder' => 'dd-mm-yyyy or yyyy-mm-dd',
31
+ );
32
+
33
+ return $field_args;
34
+
35
+ }
36
+
37
+ }
38
+
39
+ }
libraries/wp-conditions/conditions/wpc-weight-condition.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Weight_Condition' ) ) {
5
+
6
+ class WPC_Weight_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Weight', 'wpc-conditions' );
10
+ $this->slug = __( 'weight', 'wpc-conditions' );
11
+ $this->group = __( 'Cart', 'wpc-conditions' );
12
+ $this->description = __( 'Weight calculated on all the cart contents', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_value( $value ) {
18
+ // Make sure its formatted correct
19
+ return str_replace( ',', '.', $value );
20
+ }
21
+
22
+ public function get_compare_value() {
23
+ return WC()->cart->get_cart_contents_weight();
24
+ }
25
+
26
+ }
27
+
28
+ }
libraries/wp-conditions/conditions/wpc-width-condition.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Width_Condition' ) ) {
5
+
6
+ class WPC_Width_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Width', 'wpc-conditions' );
10
+ $this->slug = __( 'width', 'wpc-conditions' );
11
+ $this->group = __( 'Product', 'wpc-conditions' );
12
+ $this->description = __( 'Compared to widest product in cart', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function get_compare_value() {
18
+
19
+ $width = array();
20
+ foreach ( WC()->cart->get_cart() as $product ) :
21
+
22
+ if ( true == $product['data']->variation_has_width ) :
23
+ $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) );
24
+ else :
25
+ $width[] = ( get_post_meta( $product['product_id'], '_width', true ) );
26
+ endif;
27
+
28
+ endforeach;
29
+
30
+ return max( $width );
31
+
32
+ }
33
+
34
+ }
35
+
36
+ }
libraries/wp-conditions/conditions/wpc-zipcode-condition.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( ! class_exists( 'WPC_Zipcode_Condition' ) ) {
5
+
6
+ class WPC_Zipcode_Condition extends WPC_Condition {
7
+
8
+ public function __construct() {
9
+ $this->name = __( 'Zipcode', 'wpc-conditions' );
10
+ $this->slug = __( 'zipcode', 'wpc-conditions' );
11
+ $this->group = __( 'User', 'wpc-conditions' );
12
+ $this->description = __( 'Compare against customer zipcode. Comma separated list allowed. Use \'*\' for wildcard', 'wpc-conditions' );
13
+
14
+ parent::__construct();
15
+ }
16
+
17
+ public function match( $match, $operator, $value ) {
18
+
19
+ $zipcode = $this->get_compare_value();
20
+
21
+ // Prepare the store-owner set value
22
+ $value_zipcodes = array();
23
+ if ( preg_match( '/\, ?/', $value ) ) :
24
+
25
+ foreach ( preg_split( '/\, ?/', $value ) as $v ) :
26
+ $value_zipcodes[] = preg_replace( '/[^0-9a-zA-Z\-]/', '', $v );
27
+ endforeach;
28
+
29
+ else :
30
+ $value_zipcodes[] = preg_replace( '/[^0-9a-zA-Z\-]/', '', $value );
31
+ endif;
32
+
33
+ // Match zipcode
34
+ if ( '==' == $operator ) :
35
+
36
+ foreach ( $value_zipcodes as $zip ) :
37
+ if ( $match = preg_match( '/^' . preg_quote( $zip, '/' ) . '/i', $zipcode ) ) :
38
+ break;
39
+ endif;
40
+ endforeach;
41
+
42
+ elseif ( '!=' == $operator ) :
43
+
44
+ $match = true;
45
+ foreach ( $value_zipcodes as $zip ) :
46
+ if ( $match = ! preg_match( '/^' . preg_quote( $zip, '/' ) . '/i', $zipcode ) ) :
47
+ break;
48
+ endif;
49
+ endforeach;
50
+
51
+ elseif ( '>=' == $operator ) :
52
+
53
+ foreach ( $value_zipcodes as $zip ) :
54
+
55
+ if ( $match = ( $zipcode >= $zip ) ) :
56
+ break;
57
+ endif;
58
+ endforeach;
59
+
60
+ elseif ( '<=' == $operator ) :
61
+
62
+ foreach ( $value_zipcodes as $zip ) :
63
+
64
+ if ( $match = ( $zipcode <= $zip ) ) :
65
+ break;
66
+ endif;
67
+ endforeach;
68
+
69
+ endif;
70
+
71
+ return $match;
72
+
73
+ }
74
+
75
+ public function get_compare_value() {
76
+ return preg_replace( '/[^0-9a-zA-Z\-]/', '', WC()->customer->get_shipping_postcode() );
77
+ }
78
+
79
+ }
80
+
81
+ }
libraries/wp-conditions/functions.php ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ if ( is_admin() ) {
5
+ require_once plugin_dir_path( __FILE__ ) . 'admin-functions.php';
6
+ }
7
+
8
+ require_once 'conditions/wpc-condition.php';
9
+ require_once 'conditions/wpc-fallback-condition.php';
10
+
11
+ // General
12
+ require_once 'conditions/wpc-page-condition.php';
13
+ require_once 'conditions/wpc-day-condition.php';
14
+ require_once 'conditions/wpc-date-condition.php';
15
+ require_once 'conditions/wpc-time-condition.php';
16
+
17
+ require_once 'conditions/wpc-subtotal-condition.php';
18
+ require_once 'conditions/wpc-subtotal-ex-tax-condition.php';
19
+ require_once 'conditions/wpc-tax-condition.php';
20
+ require_once 'conditions/wpc-quantity-condition.php';
21
+ require_once 'conditions/wpc-contains-product-condition.php';
22
+ require_once 'conditions/wpc-coupon-condition.php';
23
+ require_once 'conditions/wpc-weight-condition.php';
24
+ require_once 'conditions/wpc-contains-shipping-class-condition.php';
25
+ require_once 'conditions/wpc-contains-category-condition.php';
26
+ require_once 'conditions/wpc-shipping-method-condition.php';
27
+ require_once 'conditions/wpc-payment-gateway-condition.php';
28
+
29
+ require_once 'conditions/wpc-zipcode-condition.php';
30
+ require_once 'conditions/wpc-city-condition.php';
31
+ require_once 'conditions/wpc-state-condition.php';
32
+ require_once 'conditions/wpc-country-condition.php';
33
+ require_once 'conditions/wpc-role-condition.php';
34
+
35
+ require_once 'conditions/wpc-length-condition.php';
36
+ require_once 'conditions/wpc-width-condition.php';
37
+ require_once 'conditions/wpc-height-condition.php';
38
+ require_once 'conditions/wpc-stock-status-condition.php';
39
+ require_once 'conditions/wpc-stock-condition.php';
40
+ require_once 'conditions/wpc-category-condition.php';
41
+
42
+
43
+ if ( ! function_exists( 'wpc_get_registered_conditions' ) ) {
44
+
45
+ /**
46
+ *
47
+ * @return WPC_Condition[] List of condition classes
48
+ */
49
+ function wpc_get_registered_conditions() {
50
+
51
+ $conditions = array(
52
+ new WPC_Page_Condition(),
53
+ new WPC_Day_Condition(),
54
+ new WPC_Date_Condition(),
55
+ new WPC_Time_Condition(),
56
+
57
+ new WPC_Subtotal_Condition(),
58
+ new WPC_Subtotal_Ex_Tax_Condition(),
59
+ new WPC_Tax_Condition(),
60
+ new WPC_Quantity_Condition(),
61
+ new WPC_Contains_Product_Condition(),
62
+ new WPC_Coupon_Condition(),
63
+ new WPC_Weight_Condition(),
64
+ new WPC_Contains_Shipping_Class_Condition(),
65
+ new WPC_Contains_Category_Condition(),
66
+ new WPC_Shipping_Method_Condition(),
67
+ new WPC_Payment_Gateway_Condition(),
68
+
69
+ new WPC_Zipcode_Condition(),
70
+ new WPC_City_Condition(),
71
+ new WPC_State_Condition(),
72
+ new WPC_Country_Condition(),
73
+ new WPC_Role_Condition(),
74
+
75
+ new WPC_Length_Condition(),
76
+ new WPC_Width_Condition(),
77
+ new WPC_Height_Condition(),
78
+ new WPC_Stock_Status_Condition(),
79
+ new WPC_Stock_Condition(),
80
+ new WPC_Category_Condition(),
81
+ );
82
+
83
+ return apply_filters( 'wp-conditions\registered_conditions', $conditions );
84
+
85
+ }
86
+
87
+ }
88
+
89
+
90
+ if ( ! function_exists( 'wpc_get_condition' ) ) {
91
+
92
+ /**
93
+ * Get condition instance.
94
+ *
95
+ * Get a instance of a WPC_Condition class.
96
+ *
97
+ * @since 1.0.0
98
+ *
99
+ * @param string $condition Name of the condition to get.
100
+ * @return WPC_Condition|bool WPC_Condition instance when class exists, false otherwise.
101
+ */
102
+ function wpc_get_condition( $condition ) {
103
+
104
+ $class_name = 'WPC_' . implode( '_', array_map( 'ucfirst', explode( '_', $condition ) ) ) . '_Condition';
105
+ if ( class_exists( $class_name ) ) {
106
+ return new $class_name();
107
+ } else {
108
+ return new WPC_Fallback_Condition();
109
+ }
110
+
111
+ }
112
+
113
+ }
114
+
115
+
116
+ if ( ! function_exists( 'wpc_match_conditions' ) ) {
117
+
118
+ /**
119
+ * Match conditions.
120
+ *
121
+ * Check if conditions match, if all conditions in one condition group
122
+ * matches it will return TRUE and the fee will be applied.
123
+ *
124
+ * @since 1.0.0
125
+ *
126
+ * @param array $condition_groups List of condition groups containing their conditions.
127
+ * @param array $args Arguments to pass to the matching method.
128
+ * @return BOOL TRUE if all the conditions in one of the condition groups matches true.
129
+ */
130
+ function wpc_match_conditions( $condition_groups = array(), $args = array() ) {
131
+
132
+ if ( empty( $condition_groups ) || ! is_array( $condition_groups ) ) :
133
+ return false;
134
+ endif;
135
+
136
+ foreach ( $condition_groups as $condition_group => $conditions ) :
137
+
138
+ $match_condition_group = true;
139
+
140
+ foreach ( $conditions as $condition ) :
141
+
142
+ $condition = apply_filters( 'wp-conditions\condition', $condition ); // BC helper
143
+ $wpc_condition = wpc_get_condition( $condition['condition'] );
144
+
145
+ // Match the condition - pass any custom ($)args as parameters.
146
+ $match = call_user_func_array( array( $wpc_condition, 'match' ), array( false, $condition['operator'], $condition['value'], $args ) );
147
+
148
+ // Filter the matched result - BC helper
149
+ $parameters = array( 'wp-conditions\condition\match', $match, $condition['condition'], $condition['operator'], $condition['value'], $args );
150
+ $match = call_user_func_array( 'apply_filters', $parameters );
151
+
152
+ // Original - simple - way
153
+ // $match = $wpc_condition->match( false, $condition['operator'], $condition['value'] );
154
+ // $match = apply_filters( 'wp-conditions\condition\match', $match, $condition['condition'], $condition['operator'], $condition['value'] );
155
+
156
+ if ( false == $match ) :
157
+ $match_condition_group = false;
158
+ endif;
159
+
160
+ endforeach;
161
+
162
+ // return true if one condition group matches
163
+ if ( true == $match_condition_group ) :
164
+ return true;
165
+ endif;
166
+
167
+ endforeach;
168
+
169
+ return false;
170
+
171
+ }
172
+
173
+ }
174
+
175
+
176
+ if ( ! function_exists( 'wpc_sanitize_conditions' ) ) {
177
+
178
+ /**
179
+ * Sanitize conditions.
180
+ *
181
+ * Go over all the conditions and sanitize them. Used when the conditions are being saved.
182
+ *
183
+ * @since 1.0.0
184
+ *
185
+ * @param array $conditions The list of conditions.
186
+ * @return array
187
+ */
188
+ function wpc_sanitize_conditions( $conditions ) {
189
+
190
+ $sanitized_conditions = array();
191
+ foreach ( $conditions as $group_key => $condition_group ) :
192
+ if ( $group_key == '9999' ) continue; // Template group
193
+
194
+ foreach ( $condition_group as $condition_id => $condition_values ) :
195
+ if ( $condition_id == '9999' ) continue; // Template condition
196
+ if ( ! isset( $condition_values['value'] ) ) $condition_values['value'] = '';
197
+
198
+ foreach ( $condition_values as $condition_key => $condition_value ) :
199
+
200
+ switch ( $condition_key ) :
201
+
202
+ default :
203
+ $condition_value = sanitize_text_field( $condition_value );
204
+ break;
205
+
206
+ case 'condition' :
207
+ $condition_value = sanitize_key( $condition_value );
208
+ break;
209
+
210
+ case 'operator' :
211
+ $condition_value = in_array( $condition_value, array( '==', '!=', '>=', '<=' ) ) ? $condition_value : '==';
212
+ break;
213
+
214
+ case 'value' :
215
+ if ( is_array( $condition_value ) ) :
216
+ $condition_value = array_map( 'sanitize_text_field', $condition_value );
217
+ elseif ( is_string( $condition_value ) ) :
218
+ $condition_value = sanitize_text_field( $condition_value );
219
+ endif;
220
+ break;
221
+
222
+ endswitch;
223
+
224
+ $sanitized_conditions[ $group_key ][ $condition_id ][ $condition_key ] = $condition_value;
225
+
226
+ endforeach;
227
+
228
+ endforeach;
229
+
230
+ endforeach;
231
+
232
+ return $sanitized_conditions;
233
+
234
+ }
235
+
236
+ }
237
+
238
+
239
+ if ( ! function_exists( 'wpc_condition_operators' ) ) {
240
+
241
+ /**
242
+ * Get all condition operators.
243
+ *
244
+ * Get a list of the available operators for all the conditions.
245
+ * Mainly used to determine which operators to show per condition.
246
+ *
247
+ * @since 1.0.0
248
+ *
249
+ * @return array List of condition operators.
250
+ */
251
+ function wpc_condition_operators() {
252
+
253
+ $condition_operators = array(
254
+ // Add default for when a custom condition doesn't properly add the available operators
255
+ 'default' => array(
256
+ '==' => __( 'Equal to', 'wpc-conditions' ),
257
+ '!=' => __( 'Not equal to', 'wpc-conditions' ),
258
+ '>=' => __( 'Greater or equal to', 'wpc-conditions' ),
259
+ '<=' => __( 'Less or equal to ', 'wpc-conditions' ),
260
+ ),
261
+ );
262
+
263
+ foreach ( wpc_get_registered_conditions() as $condition ) {
264
+ $condition_operators[ $condition->get_slug() ] = $condition->get_available_operators();
265
+ }
266
+
267
+ return apply_filters( 'wp-conditions\condition_operators', $condition_operators );
268
+
269
+ }
270
+
271
+ }
272
+
273
+ if ( ! function_exists( 'wpc_condition_descriptions' ) ) {
274
+
275
+ /**
276
+ * Get all condition operators.
277
+ *
278
+ * Get a list of the available operators for all the conditions.
279
+ * Mainly used to determine which operators to show per condition.
280
+ *
281
+ * @since 1.0.0
282
+ *
283
+ * @return array List of condition operators.
284
+ */
285
+ function wpc_condition_descriptions() {
286
+
287
+ $condition_descriptions = array();
288
+
289
+ foreach ( wpc_get_registered_conditions() as $condition ) {
290
+ $condition_descriptions[ $condition->get_slug() ] = $condition->get_description();
291
+ }
292
+
293
+ return apply_filters( 'wp-conditions\condition_descriptions', $condition_descriptions );
294
+
295
+ }
296
+
297
+ }
readme.txt CHANGED
@@ -1,33 +1,41 @@
1
  === WooCommerce Advanced Free Shipping ===
2
  Contributors: sormano
3
- Tags: woocommerce, shipping, woocommerce shipping, woocommerce free shipping, woocommerce free, woocommerce advanced free shipping, wc free shipping, wc shipping, advanced shipping, pro shipping, table rate shipping, country shipping, free shipping
4
  Requires at least: 4.0
5
- Tested up to: 4.6
6
- Stable tag: 1.0.11
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
10
  WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
11
 
12
  == Description ==
13
- WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
 
 
 
 
14
 
 
15
  *Conditions like:*
16
 
17
- - Cart total
 
 
18
  - Country
19
- - Zip code
20
- - Stock / stock status
 
21
  - Weight
22
- - Quantity
23
- - Coupon
24
  - many, many more...
25
 
 
 
26
  **Look at the screenshots!**
27
 
28
  > **Applying shipping cost**<br /><br />
29
  > Have you given this plugin a shot and like how you can set things up?<br />
30
- > Another plugin is available that allows you to setup shipping cost with the same conditional logic options as this plugin!<br /><br />
31
  > **Features:**<br />
32
  > - Add shipping cost to the shipping rates<br />
33
  > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- *Per weight*<br />
@@ -42,14 +50,23 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
42
  > - Create shipping zones<br />
43
  > - Set tax status<br />
44
  > <br />
45
- > View [WooCommerce Advanced Shipping](http://codecanyon.net/item/woocommerce-advanced-shipping/8634573)
46
 
47
- **Translations, feature requests, ratings and donations are welcome and appreciated!**
 
 
 
 
 
 
 
48
 
49
  **Translations**
50
 
51
- - Spanish [(Andres Felipe)](https://wordpress.org/support/profile/naturalworldstm)
52
- - Italian (Stefano Callisto)
 
 
53
 
54
  == Installation ==
55
 
@@ -57,14 +74,44 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
57
  2. Activate the plugin through the 'Plugins' menu in WordPress
58
  3. Go to the settings page to fine-tune the settings if desired
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  == Screenshots ==
61
 
62
- 1. WooCommerce Shipping options
63
- 2. WAFS shipping conditions
64
- 3. WAFS shipping conditions possibilities
 
65
 
66
  == Changelog ==
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  = 1.0.11 - 05-09-2016 =
69
 
70
  * [Fix] - State condition field only displayed states of the last country
@@ -101,7 +148,7 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
101
  = 1.0.6 - 04-06-2015 =
102
 
103
  * [Add] - Escaping/sanitizing to different elements
104
- * Improvement - Shipping class matching function now uses varation shiping class instead of the parents'
105
  * [i18n] - Add Italian translation
106
 
107
  = 1.0.5 - 14-12-2014 =
@@ -111,38 +158,38 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
111
  * Improvement - Add background color to overview table every other row
112
 
113
  = 1.0.4 =
114
- * Fix - Weight condition wasn't working
115
- * Fix - Cash On Delivery for WAFS
116
- * Added - Added languages files for Portuguese - Brazil pt_BR
117
 
118
  = 1.0.3 =
119
- * Improvement - Customized user messages when saving shipping method
120
- * Improvement - Updated some comments to comment standards
121
- * Improvement - Overview not showing all actions when hovering only one
122
- * Improvement - Added ABSPATH check to each file
123
- * Improvement - Improved code comments
124
- * Improvement - Remove globals, use WAFS() function now
125
- * Improvement - Zip codes are now better detected (only integer values)
126
- * Improvement - Load textdomains
127
- * Improvement - Add compatibility for custom value fields
128
- * Improvement - Add world wide state support
129
- * Fix - No notice on shipping title in DEBUG mode
130
- * Fix - Loading icon on sub directory websites
131
- * Fix - Condition description didn't show sometimes
132
- * Fix - 'Category' - 'Not equal to' error
133
- * Fix - Showing drafts in overview
134
- * Removed - Author from overview, who needs that?
135
 
136
 
137
  = 1.0.2 = 07/03/2014
138
- * Added - support for comma separated zip codes
139
- * Added - filter for condition values
140
- * Added - filter for condition descriptions
141
 
142
 
143
  = 1.0.1 =
144
- * Fix - Wrongful url for sub-domain websites
145
- * Add - Added states as condition
146
 
147
  = 1.0.0 =
148
  * Initial release
1
  === WooCommerce Advanced Free Shipping ===
2
  Contributors: sormano
3
+ Tags: woocommerce shipping, woocommerce, shipping, woocommerce free shipping, woocommerce free, woocommerce advanced free shipping, wc free shipping, wc shipping, advanced shipping, pro shipping, table rate shipping, country shipping, free shipping
4
  Requires at least: 4.0
5
+ Tested up to: 4.7.3
6
+ Stable tag: 1.1.0
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
10
  WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
11
 
12
  == Description ==
13
+ With the WooCommerce Advanced Free Shipping plugin you can setup your own advanced rules to determine when a free shipping rate should be available for the customer.
14
+ This plugin will give you full control over your free WooCommerce shipping rates.
15
+
16
+ Within each shipping rate you can create multiple 'OR' condition groups with multiple 'AND' conditions inside each group. This means that it is very easy to setup a
17
+ free shipping rate for multiple user roles in one shipping rate for example.
18
 
19
+ There are many default shipping conditions available.
20
  *Conditions like:*
21
 
22
+ - Subtotal
23
+ - Quantity
24
+ - User role
25
  - Country
26
+ - Zipcode
27
+ - Shipping class
28
+ - Category
29
  - Weight
 
 
30
  - many, many more...
31
 
32
+ Not there what you're looking for? The plugin has been made to be easily extensible, meaning you can also add your own custom conditions through code snippets!
33
+
34
  **Look at the screenshots!**
35
 
36
  > **Applying shipping cost**<br /><br />
37
  > Have you given this plugin a shot and like how you can set things up?<br />
38
+ > I've build another plugin that allows you to setup shipping cost with the same conditional logic power as this plugin!<br /><br />
39
  > **Features:**<br />
40
  > - Add shipping cost to the shipping rates<br />
41
  > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- *Per weight*<br />
50
  > - Create shipping zones<br />
51
  > - Set tax status<br />
52
  > <br />
53
+ > View [Advanced Shipping for WooCommerce](http://codecanyon.net/item/woocommerce-advanced-shipping/8634573)
54
 
55
+ **Showing a free shipping threshold message**
56
+
57
+ There are a few plugins out there that add a message when someone hasn't reached the free shipping threshold yet. These plugin work on the 'Free shipping' option that is provided in WooCommerce by default.
58
+ It is unlikely that these plugins will work out of the box with Advanced Free Shipping due to the complexity of the conditional logic.
59
+
60
+ In case you do want to show this kind of message, The [Advanced Messages for WooCommerce](https://shopplugins.com/plugins/woocommerce-advanced-messages/ ) plugin allows you to setup a message with the same type of conditions, allowing you to setup the messages according to the same needs as the free shipping options.
61
+
62
+ **Translations, feature requests and ratings are welcome and appreciated!**
63
 
64
  **Translations**
65
 
66
+ - Spanish
67
+ - Italian
68
+ - Portuguese (Brazil / Portugal)
69
+ - Greek
70
 
71
  == Installation ==
72
 
74
  2. Activate the plugin through the 'Plugins' menu in WordPress
75
  3. Go to the settings page to fine-tune the settings if desired
76
 
77
+ == Frequently Asked Questions ==
78
+
79
+ = Can I setup partial free shipping? =
80
+
81
+ The short answer to this is 'no', the long answer comes down to 'possibly'. I wrote a full length blog post about this here:
82
+ [Apply free shipping for specific products in WooCommerce](http://jeroensormani.com/apply-free-shipping-for-specific-products-in-woocommerce/)
83
+
84
+ = Can multiple free shipping options show simultaneously? =
85
+
86
+ The current version of the plugin - 1.1.0 - doesn't have the ability to show multiple Advanced Free Shipping rates at the same time.
87
+ During first development I made the - in hindsight - wrong decision thinking "Why would anyone need multiple WooCommerce free shipping options at the same time".
88
+ In the future this will likely be changed, for now I recommend taking a look at the [Advanced Shipping for WooCommerce](http://codecanyon.net/item/woocommerce-advanced-shipping/8634573) plugin which does have the ability to show all rates that match the conditions.
89
+
90
+ = The shipping rates I setup are not showing at the cart/check, why? =
91
+
92
+
93
  == Screenshots ==
94
 
95
+ 1. WooCommerce Shipping options overview
96
+ 2. WooCommerce Shipping rate example
97
+ 3. WooCommerce Shipping rate all available conditions
98
+ 4. WooCommerce Shipping condition available operators
99
 
100
  == Changelog ==
101
 
102
+ = 1.1.0 - 06-03-2017 = IMPORTANT NOTE - As of this version, the plugin requires PHP 5.3 or higher to function
103
+
104
+ * [Fix] - Allow variations to be set (and make them working) with the 'contains product' condition
105
+ * [Fix] - Prevent duplicate DB query
106
+ * [Improvement] - BIG refactor of the backend conditions - please verify your setup if using custom coded condition
107
+ * [Improvement] - Smoother User Experience with conditions
108
+ - Instant adding of conditions / condition groups
109
+ - Only show valid operator options
110
+ - Instantly show condition descriptions
111
+ - Deleting entire condition groups
112
+ - Duplicate condition groups
113
+ * [Improvement] - WC 2.7 compatibility changes
114
+
115
  = 1.0.11 - 05-09-2016 =
116
 
117
  * [Fix] - State condition field only displayed states of the last country
148
  = 1.0.6 - 04-06-2015 =
149
 
150
  * [Add] - Escaping/sanitizing to different elements
151
+ * [Improvement] - Shipping class matching function now uses variation shipping class instead of the parents'
152
  * [i18n] - Add Italian translation
153
 
154
  = 1.0.5 - 14-12-2014 =
158
  * Improvement - Add background color to overview table every other row
159
 
160
  = 1.0.4 =
161
+ * [Fix] - Weight condition wasn't working
162
+ * [Fix] - Cash On Delivery for WAFS
163
+ * [Add] - Added languages files for Portuguese - Brazil pt_BR
164
 
165
  = 1.0.3 =
166
+ * [Improvement] - Customized user messages when saving shipping method
167
+ * [Improvement] - Updated some comments to comment standards
168
+ * [Improvement] - Overview not showing all actions when hovering only one
169
+ * [Improvement] - Added ABSPATH check to each file
170
+ * [Improvement] - Improved code comments
171
+ * [Improvement] - Remove globals, use WAFS() function now
172
+ * [Improvement] - Zip codes are now better detected (only integer values)
173
+ * [Improvement] - Load textdomains
174
+ * [Improvement] - Add compatibility for custom value fields
175
+ * [Improvement] - Add world wide state support
176
+ * [Fix] - No notice on shipping title in DEBUG mode
177
+ * [Fix] - Loading icon on sub directory websites
178
+ * [Fix] - Condition description didn't show sometimes
179
+ * [Fix] - 'Category' - 'Not equal to' error
180
+ * [Fix] - Showing drafts in overview
181
+ * [Removed] - Author from overview, who needs that?
182
 
183
 
184
  = 1.0.2 = 07/03/2014
185
+ * [Added] - support for comma separated zip codes
186
+ * [Added] - filter for condition values
187
+ * [Added] - filter for condition descriptions
188
 
189
 
190
  = 1.0.1 =
191
+ * [Fix] - Wrongful url for sub-domain websites
192
+ * [Add] - Added states as condition
193
 
194
  = 1.0.0 =
195
  * Initial release
woocommerce-advanced-free-shipping.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WooCommerce Advanced Free Shipping
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-advanced-free-shipping/
5
  * Description: WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
6
- * Version: 1.0.11
7
  * Author: Jeroen Sormani
8
  * Author URI: http://jeroensormani.com/
9
  * Text Domain: woocommerce-advanced-free-shipping
@@ -48,7 +48,7 @@ class WooCommerce_Advanced_Free_Shipping {
48
  * @since 1.0.4
49
  * @var string $version Plugin version number.
50
  */
51
- public $version = '1.0.11';
52
 
53
 
54
  /**
@@ -88,8 +88,6 @@ class WooCommerce_Advanced_Free_Shipping {
88
  endif;
89
  endif;
90
 
91
- $this->init();
92
-
93
  }
94
 
95
 
@@ -123,6 +121,10 @@ class WooCommerce_Advanced_Free_Shipping {
123
  */
124
  public function init() {
125
 
 
 
 
 
126
  // Add hooks/filters
127
  $this->hooks();
128
 
@@ -132,6 +134,8 @@ class WooCommerce_Advanced_Free_Shipping {
132
  // Updater
133
  $this->update();
134
 
 
 
135
  // Functions
136
  require_once plugin_dir_path( __FILE__ ) . 'includes/core-functions.php';
137
 
@@ -157,10 +161,9 @@ class WooCommerce_Advanced_Free_Shipping {
157
  * Admin class
158
  */
159
  if ( is_admin() ) :
160
- require_once plugin_dir_path( __FILE__ ) . 'includes/admin/admin-functions.php';
161
-
162
  require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-wafs-admin.php';
163
  $this->admin = new WAFS_Admin();
 
164
  endif;
165
 
166
  }
@@ -212,7 +215,7 @@ class WooCommerce_Advanced_Free_Shipping {
212
  add_action( 'woocommerce_shipping_init', array( $this, 'wafs_free_shipping' ) );
213
 
214
  // Add shipping method
215
- add_action( 'woocommerce_shipping_methods', array( $this, 'wafs_add_shipping_method' ) );
216
 
217
  }
218
 
@@ -269,19 +272,20 @@ class WooCommerce_Advanced_Free_Shipping {
269
 
270
 
271
  /**
272
- * Enqueue scripts.
273
  *
274
- * Enqueue javascript and stylesheets to the admin area.
275
  *
276
- * @since 1.0.0
277
  */
278
- public function wafs_admin_enqueue_scripts() {
279
 
280
- _deprecated_function( __FUNCTION__, '1.0.8', 'WAFS()->admin->admin_enqueue_script()' );
 
 
281
 
282
  }
283
 
284
-
285
  }
286
 
287
 
@@ -307,4 +311,4 @@ if ( ! function_exists( 'WAFS' ) ) :
307
 
308
  endif;
309
 
310
- WAFS();
3
  * Plugin Name: WooCommerce Advanced Free Shipping
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-advanced-free-shipping/
5
  * Description: WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
6
+ * Version: 1.1.0
7
  * Author: Jeroen Sormani
8
  * Author URI: http://jeroensormani.com/
9
  * Text Domain: woocommerce-advanced-free-shipping
48
  * @since 1.0.4
49
  * @var string $version Plugin version number.
50
  */
51
+ public $version = '1.1.0';
52
 
53
 
54
  /**
88
  endif;
89
  endif;
90
 
 
 
91
  }
92
 
93
 
121
  */
122
  public function init() {
123
 
124
+ if ( version_compare( PHP_VERSION, '5.3', 'lt' ) ) {
125
+ return add_action( 'admin_notices', array( $this, 'php_version_notice' ) );
126
+ }
127
+
128
  // Add hooks/filters
129
  $this->hooks();
130
 
134
  // Updater
135
  $this->update();
136
 
137
+ require_once plugin_dir_path( __FILE__ ) . '/libraries/wp-conditions/functions.php';
138
+
139
  // Functions
140
  require_once plugin_dir_path( __FILE__ ) . 'includes/core-functions.php';
141
 
161
  * Admin class
162
  */
163
  if ( is_admin() ) :
 
 
164
  require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-wafs-admin.php';
165
  $this->admin = new WAFS_Admin();
166
+ $this->admin->init();
167
  endif;
168
 
169
  }
215
  add_action( 'woocommerce_shipping_init', array( $this, 'wafs_free_shipping' ) );
216
 
217
  // Add shipping method
218
+ add_filter( 'woocommerce_shipping_methods', array( $this, 'wafs_add_shipping_method' ) );
219
 
220
  }
221
 
272
 
273
 
274
  /**
275
+ * Display PHP 5.3 required notice.
276
  *
277
+ * Display a notice when the required PHP version is not met.
278
  *
279
+ * @since 1.0.6
280
  */
281
+ public function php_version_notice() {
282
 
283
+ ?><div class='updated'>
284
+ <p><?php echo sprintf( __( 'Advanced Free Shipping requires PHP 5.3 or higher and your current PHP version is %s. Please (contact your host to) update your PHP version.', 'woocommerce-advanced-messages' ), PHP_VERSION ); ?></p>
285
+ </div><?php
286
 
287
  }
288
 
 
289
  }
290
 
291
 
311
 
312
  endif;
313
 
314
+ WAFS()->init();