Version Description
25-08-2016 =
[Improvement] - Optimized asset scripts
[Improvement] - Refactored condition code (backend)
[Improvement] - Allow asterisk (*) in zipcode to allow 'begins with' type of matching functionality
[Improvement] - Allow dollar and percentage signs in the 'coupon' condition to setup the condition based on the amounts instead of solely coupon codes
[Improvement] - Add a link to the shipping rates overview page on the plugins page
[Improvement] - Add support for continents in the 'country' condition (requires WC 2.6+)
[Improvement] - Improved 'product' condition value fields (allow searching) and supports huge amounts of product
[Improvement] - Allow comma separated cities
Download this release
Release Info
Developer | sormano |
Plugin | WooCommerce Advanced Free Shipping |
Version | 1.0.10 |
Comparing to | |
See all releases |
Code changes from version 1.0.9 to 1.0.10
- assets/css/parts/wp-conditions.scss +187 -0
- assets/css/woocommerce-advanced-free-shipping.min.css +1 -0
- assets/css/{admin-style.css → woocommerce-advanced-free-shipping.scss} +2 -0
- assets/js/wafs-js.js +0 -83
- assets/js/woocommerce-advanced-free-shipping.js +104 -0
- assets/js/woocommerce-advanced-free-shipping.min.js +1 -0
- codeoversight.yml +39 -0
- includes/admin/admin-functions.php +100 -0
- includes/admin/class-wafs-admin.php +42 -7
- includes/admin/class-wafs-condition.php +350 -0
- includes/admin/settings/conditions/class-wafs-condition.php +0 -227
- includes/admin/settings/conditions/condition-conditions.php +0 -68
- includes/admin/settings/conditions/condition-descriptions.php +0 -49
- includes/admin/settings/conditions/condition-operators.php +0 -40
- includes/admin/settings/conditions/condition-values.php +0 -250
- includes/admin/settings/meta-box-conditions.php +0 -55
- includes/admin/views/conditions-table.php +17 -19
- includes/admin/views/html-condition-row.php +61 -0
- includes/admin/views/meta-box-conditions.php +43 -0
- includes/admin/{settings → views}/meta-box-settings.php +8 -3
- includes/class-wafs-ajax.php +40 -22
- includes/class-wafs-match-conditions.php +169 -45
- includes/class-wafs-method.php +5 -5
- includes/class-wafs-post-type.php +9 -9
- includes/core-functions.php +30 -0
- readme.txt +13 -2
- woocommerce-advanced-free-shipping.php +10 -5
assets/css/parts/wp-conditions.scss
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* WPC 1.0.1
|
3 |
+
*/
|
4 |
+
|
5 |
+
/**************************************************************
|
6 |
+
* Conditions
|
7 |
+
*************************************************************/
|
8 |
+
.wpc-conditions {
|
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;
|
40 |
+
}
|
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
|
54 |
+
.wpc-condition-delete {
|
55 |
+
display: none;
|
56 |
+
opacity: 0;
|
57 |
+
transition: opacity .3s ease-in-out;
|
58 |
+
}
|
59 |
+
.wpc-condition-wrap:hover .wpc-condition-delete {
|
60 |
+
display: inline-block;
|
61 |
+
opacity: 1;
|
62 |
+
}
|
63 |
+
|
64 |
+
// Load icon
|
65 |
+
.wpc-condition-wrap.loading {
|
66 |
+
height: 30px;
|
67 |
+
|
68 |
+
.loading-icon {
|
69 |
+
width: 100%;
|
70 |
+
clear: both;
|
71 |
+
display: block;
|
72 |
+
text-align: center;
|
73 |
+
line-height: 110%;
|
74 |
+
margin: 0 1px;
|
75 |
+
}
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
|
80 |
+
/**************************************************************
|
81 |
+
* Select2
|
82 |
+
*************************************************************/
|
83 |
+
.wpc-condition-wrap {
|
84 |
+
|
85 |
+
.wpc-value.select2-container {
|
86 |
+
display: inline-block !important;
|
87 |
+
margin: 1px;
|
88 |
+
|
89 |
+
&.select2-container-active .select2-choice {
|
90 |
+
border: 1px solid #666;
|
91 |
+
}
|
92 |
+
&.select2-drop-above .select2-choice {
|
93 |
+
border-radius: 0 0 4px 4px;
|
94 |
+
border: 1px solid #666;
|
95 |
+
border-top-color: rgba(0, 0, 0, 0);
|
96 |
+
}
|
97 |
+
.select2-choice {
|
98 |
+
border-color: #ddd;
|
99 |
+
-webkit-border-radius: 5px;
|
100 |
+
-moz-border-radius: 5px;
|
101 |
+
border-radius: 5px;
|
102 |
+
height: 26px;
|
103 |
+
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
|
104 |
+
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
|
105 |
+
}
|
106 |
+
}
|
107 |
+
.wpc-value.select2-dropdown-open .select2-choice {
|
108 |
+
border-bottom-color: rgba(0, 0, 0, 0);
|
109 |
+
-webkit-box-shadow: 0 1px 0 #fff inset;
|
110 |
+
box-shadow: 0 1px 0 #fff inset;
|
111 |
+
border-bottom-left-radius: 0;
|
112 |
+
border-bottom-right-radius: 0;
|
113 |
+
border: 1px solid #666;
|
114 |
+
outline: 0;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
|
119 |
+
/************************
|
120 |
+
* Table / overview
|
121 |
+
***********************/
|
122 |
+
.wpc-conditions-post-table {
|
123 |
+
|
124 |
+
.sort {
|
125 |
+
padding: 0 4px;
|
126 |
+
cursor: move;
|
127 |
+
text-align: center;
|
128 |
+
vertical-align: middle;
|
129 |
+
|
130 |
+
&:before {
|
131 |
+
content: "\e032";
|
132 |
+
font-family: WooCommerce;
|
133 |
+
text-align: center;
|
134 |
+
line-height: 1;
|
135 |
+
color: #999;
|
136 |
+
display: block;
|
137 |
+
width: 100%;
|
138 |
+
float: left;
|
139 |
+
height: 100%;
|
140 |
+
}
|
141 |
+
}
|
142 |
+
.sort:before,
|
143 |
+
.row-actions {
|
144 |
+
visibility: hidden !important;
|
145 |
+
}
|
146 |
+
tr:hover .sort:before,
|
147 |
+
tr:hover > td > .row-actions {
|
148 |
+
visibility: visible !important;
|
149 |
+
}
|
150 |
+
|
151 |
+
/* WooCommerce Add icon */
|
152 |
+
.add.button:before {
|
153 |
+
font-family: WooCommerce;
|
154 |
+
speak: none;
|
155 |
+
font-weight: 400;
|
156 |
+
font-variant: normal;
|
157 |
+
text-transform: none;
|
158 |
+
line-height: 1;
|
159 |
+
-webkit-font-smoothing: antialiased;
|
160 |
+
margin-right: 7px;
|
161 |
+
content: "\e007";
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
|
166 |
+
// Currency
|
167 |
+
.wpc-currency {
|
168 |
+
padding: 3px 10px;
|
169 |
+
font-size: 14px;
|
170 |
+
font-weight: 400;
|
171 |
+
line-height: 19px;
|
172 |
+
height: 19px;
|
173 |
+
color: #555;
|
174 |
+
text-align: center;
|
175 |
+
background-color: #EEE;
|
176 |
+
border: 1px solid #DDD;
|
177 |
+
border-right: none;
|
178 |
+
border-radius: 4px 0px 0px 4px;
|
179 |
+
margin: 1px 0px 1px 1px;
|
180 |
+
display: inline-block;
|
181 |
+
|
182 |
+
& + input {
|
183 |
+
margin-left: -4px;
|
184 |
+
line-height: 19px ;
|
185 |
+
width: 161px !important;
|
186 |
+
}
|
187 |
+
}
|
assets/css/woocommerce-advanced-free-shipping.min.css
ADDED
@@ -0,0 +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:19px;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}
|
assets/css/{admin-style.css → woocommerce-advanced-free-shipping.scss}
RENAMED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
/* Hide visibility from admin */
|
2 |
.post-type-wafs .misc-pub-visibility#visibility {
|
3 |
display: none;
|
1 |
+
@import 'parts/wp-conditions';
|
2 |
+
|
3 |
/* Hide visibility from admin */
|
4 |
.post-type-wafs .misc-pub-visibility#visibility {
|
5 |
display: none;
|
assets/js/wafs-js.js
DELETED
@@ -1,83 +0,0 @@
|
|
1 |
-
jQuery( function( $ ) {
|
2 |
-
|
3 |
-
var loading_icon = '<span class="loading-icon"><img src="images/wpspin_light.gif"/></span>';
|
4 |
-
|
5 |
-
// Add condition
|
6 |
-
$( '#wafs_conditions' ).on( 'click', '.condition-add', function() {
|
7 |
-
|
8 |
-
var data = { action: 'wafs_add_condition', group: $( this ).attr( 'data-group' ), nonce: wafs.nonce };
|
9 |
-
|
10 |
-
$( '.condition-group-' + data.group ).append( loading_icon ).children( ':last' );
|
11 |
-
|
12 |
-
$.post( ajaxurl, data, function( response ) {
|
13 |
-
$( '.condition-group-' + data.group ).append( response ).children( ':last' ).hide().fadeIn( 'normal' );
|
14 |
-
$( '.condition-group-' + data.group + ' .loading-icon' ).children( ':first' ).remove();
|
15 |
-
});
|
16 |
-
|
17 |
-
});
|
18 |
-
|
19 |
-
// Delete condition
|
20 |
-
$( '#wafs_conditions' ).on( 'click', '.condition-delete', function() {
|
21 |
-
|
22 |
-
if ( $( this ).closest( '.condition-group' ).children( '.wafs-condition-wrap' ).length == 1 ) {
|
23 |
-
$( this ).closest( '.condition-group' ).fadeOut( 'normal', function() { $( this ).remove(); });
|
24 |
-
|
25 |
-
} else {
|
26 |
-
$( this ).closest( '.wafs-condition-wrap' ).fadeOut( 'normal', function() { $( this ).remove(); });
|
27 |
-
}
|
28 |
-
|
29 |
-
});
|
30 |
-
|
31 |
-
// Add condition group
|
32 |
-
$( '#wafs_conditions' ).on( 'click', '.condition-group-add', function() {
|
33 |
-
|
34 |
-
// Display loading icon
|
35 |
-
$( '.wafs_conditions' ).append( loading_icon ).children( ':last' );
|
36 |
-
|
37 |
-
var data = {
|
38 |
-
action: 'wafs_add_condition_group',
|
39 |
-
group: parseInt( $( '.condition-group' ).last().attr( 'data-group') ) + 1,
|
40 |
-
nonce: wafs.nonce
|
41 |
-
};
|
42 |
-
|
43 |
-
// Insert condition group
|
44 |
-
$.post( ajaxurl, data, function( response ) {
|
45 |
-
$( '.condition-group ~ .loading-icon' ).last().remove();
|
46 |
-
$( '.wafs_conditions' ).append( response ).children( ':last' ).hide().fadeIn( 'normal' );
|
47 |
-
});
|
48 |
-
|
49 |
-
});
|
50 |
-
|
51 |
-
// Update condition values
|
52 |
-
$( '#wafs_conditions' ).on( 'change', '.wafs-condition', function () {
|
53 |
-
|
54 |
-
var data = {
|
55 |
-
action: 'wafs_update_condition_value',
|
56 |
-
id: $( this ).attr( 'data-id' ),
|
57 |
-
group: $( this ).attr( 'data-group' ),
|
58 |
-
condition: $( this ).val(),
|
59 |
-
nonce: wafs.nonce
|
60 |
-
};
|
61 |
-
|
62 |
-
var replace = '.wafs-value-wrap-' + data.id;
|
63 |
-
|
64 |
-
$( replace ).html( loading_icon );
|
65 |
-
|
66 |
-
$.post( ajaxurl, data, function( response ) {
|
67 |
-
$( replace ).replaceWith( response );
|
68 |
-
});
|
69 |
-
|
70 |
-
// Update condition description
|
71 |
-
var description = {
|
72 |
-
action: 'wafs_update_condition_description',
|
73 |
-
condition: data.condition,
|
74 |
-
nonce: wafs.nonce
|
75 |
-
};
|
76 |
-
|
77 |
-
$.post( ajaxurl, description, function( description_response ) {
|
78 |
-
$( replace + ' ~ .wafs-description' ).replaceWith( description_response );
|
79 |
-
});
|
80 |
-
|
81 |
-
});
|
82 |
-
|
83 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/js/woocommerce-advanced-free-shipping.js
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;"> </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
ADDED
@@ -0,0 +1 @@
|
|
|
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;"> </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
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
7 |
+
control_structure_parentheses_inner_whitespace: whitespace
|
8 |
+
doc_function_whitespace: no_space
|
9 |
+
else_if_whitespace: no_space
|
10 |
+
exclamation_whitespace: whitespace
|
11 |
+
force_control_structure_braces: force
|
12 |
+
function_args_separator_whitespace: whitespace
|
13 |
+
function_parentheses_inner_whitespace: whitespace
|
14 |
+
indentation_whitespace: tab
|
15 |
+
opening_doc_asterisk: double
|
16 |
+
php_tag_casing: lower
|
17 |
+
php_tags: full_php_tags
|
18 |
+
remove_double_semicolon: remove
|
19 |
+
remove_empty_trailing_leading_doc_lines: remove
|
20 |
+
semicolon_before_closing_php_tag: add
|
21 |
+
static_array_index_whitespace: no_space
|
22 |
+
string_operator_whitespace: whitespace
|
23 |
+
trailing_whitespace: remove
|
24 |
+
true_false_casing: lower
|
25 |
+
type_cast_casing: lower
|
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
|
includes/admin/admin-functions.php
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
@@ -42,6 +42,12 @@ class WAFS_Admin {
|
|
42 |
// Keep WC menu open while in WAFS edit screen
|
43 |
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
|
47 |
|
@@ -54,20 +60,24 @@ class WAFS_Admin {
|
|
54 |
*/
|
55 |
public function admin_enqueue_scripts() {
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
) );
|
62 |
|
63 |
if (
|
64 |
( isset( $_REQUEST['post'] ) && 'wafs' == get_post_type( $_REQUEST['post'] ) ) ||
|
65 |
( isset( $_REQUEST['post_type'] ) && 'wafs' == $_REQUEST['post_type'] ) ||
|
66 |
-
( isset( $_REQUEST['section'] ) && '
|
67 |
) :
|
68 |
|
69 |
-
wp_enqueue_style( '
|
70 |
-
wp_enqueue_script( '
|
71 |
wp_dequeue_script( 'autosave' );
|
72 |
|
73 |
endif;
|
@@ -113,4 +123,29 @@ class WAFS_Admin {
|
|
113 |
}
|
114 |
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
}
|
42 |
// Keep WC menu open while in WAFS edit screen
|
43 |
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
|
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 |
+
|
51 |
}
|
52 |
|
53 |
|
60 |
*/
|
61 |
public function admin_enqueue_scripts() {
|
62 |
|
63 |
+
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
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 (
|
74 |
( isset( $_REQUEST['post'] ) && 'wafs' == get_post_type( $_REQUEST['post'] ) ) ||
|
75 |
( isset( $_REQUEST['post_type'] ) && 'wafs' == $_REQUEST['post_type'] ) ||
|
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;
|
123 |
}
|
124 |
|
125 |
|
126 |
+
/**
|
127 |
+
* Plugin action links.
|
128 |
+
*
|
129 |
+
* Add links to the plugins.php page below the plugin name
|
130 |
+
* and besides the 'activate', 'edit', 'delete' action links.
|
131 |
+
*
|
132 |
+
* @since 1.0.10
|
133 |
+
*
|
134 |
+
* @param array $links List of existing links.
|
135 |
+
* @param string $file Name of the current plugin being looped.
|
136 |
+
* @return array List of modified links.
|
137 |
+
*/
|
138 |
+
public function add_plugin_action_links( $links, $file ) {
|
139 |
+
|
140 |
+
if ( $file == plugin_basename( WAFS()->file ) ) :
|
141 |
+
$links = array_merge( array(
|
142 |
+
'<a href="' . esc_url( admin_url( '/admin.php?page=wc-settings&tab=shipping§ion=advanced_free_shipping' ) ) . '">' . __( 'Settings', 'woocommerce-advanced-free-shipping' ) . '</a>'
|
143 |
+
), $links );
|
144 |
+
endif;
|
145 |
+
|
146 |
+
return $links;
|
147 |
+
|
148 |
+
}
|
149 |
+
|
150 |
+
|
151 |
}
|
includes/admin/class-wafs-condition.php
ADDED
@@ -0,0 +1,350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Condition class.
|
6 |
+
*
|
7 |
+
* Represents a single condition in a condition group.
|
8 |
+
*
|
9 |
+
* @author Jeroen Sormani
|
10 |
+
* @version 1.0.0
|
11 |
+
*/
|
12 |
+
class WAFS_Condition {
|
13 |
+
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Condition ID.
|
17 |
+
*
|
18 |
+
* @since 1.0.0
|
19 |
+
* @var string $id Condition ID.
|
20 |
+
*/
|
21 |
+
public $id;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Condition.
|
25 |
+
*
|
26 |
+
* @since 1.0.0
|
27 |
+
* @var string $condition Condition slug.
|
28 |
+
*/
|
29 |
+
public $condition;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Operator.
|
33 |
+
*
|
34 |
+
* @since 1.0.0
|
35 |
+
* @var string $operator Operator slug.
|
36 |
+
*/
|
37 |
+
public $operator;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Value.
|
41 |
+
*
|
42 |
+
* @since 1.0.0
|
43 |
+
* @var string $value Condition value.
|
44 |
+
*/
|
45 |
+
public $value;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Group ID.
|
49 |
+
*
|
50 |
+
* @since 1.0.0
|
51 |
+
* @var string $group Condition group ID.
|
52 |
+
*/
|
53 |
+
public $group;
|
54 |
+
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Constructor.
|
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;
|
65 |
+
$this->condition = $condition;
|
66 |
+
$this->operator = $operator;
|
67 |
+
$this->value = $value;
|
68 |
+
|
69 |
+
if ( ! $id ) {
|
70 |
+
$this->id = rand();
|
71 |
+
}
|
72 |
+
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Output condition row.
|
78 |
+
*
|
79 |
+
* Output the full condition row which includes: condition, operator, value, add/delete buttons and
|
80 |
+
* the description.
|
81 |
+
*
|
82 |
+
* @since 1.1.6
|
83 |
+
*/
|
84 |
+
public function output_condition_row() {
|
85 |
+
|
86 |
+
$wp_condition = $this;
|
87 |
+
require 'views/html-condition-row.php';
|
88 |
+
|
89 |
+
}
|
90 |
+
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Get conditions.
|
94 |
+
*
|
95 |
+
* Get a list with the available conditions.
|
96 |
+
*
|
97 |
+
* @since 1.1.6
|
98 |
+
*
|
99 |
+
* @return array List of available conditions for a condition row.
|
100 |
+
*/
|
101 |
+
public function get_conditions() {
|
102 |
+
|
103 |
+
$conditions = array(
|
104 |
+
__( 'Cart', 'woocommerce-advanced-free-shipping' ) => array(
|
105 |
+
'subtotal' => __( 'Subtotal', 'woocommerce-advanced-free-shipping' ),
|
106 |
+
'subtotal_ex_tax' => __( 'Subtotal ex. taxes', 'woocommerce-advanced-free-shipping' ),
|
107 |
+
'tax' => __( 'Tax', 'woocommerce-advanced-free-shipping' ),
|
108 |
+
'quantity' => __( 'Quantity', 'woocommerce-advanced-free-shipping' ),
|
109 |
+
'contains_product' => __( 'Contains product', 'woocommerce-advanced-free-shipping' ),
|
110 |
+
'coupon' => __( 'Coupon', 'woocommerce-advanced-free-shipping' ),
|
111 |
+
'weight' => __( 'Weight', 'woocommerce-advanced-free-shipping' ),
|
112 |
+
'contains_shipping_class' => __( 'Contains shipping class', 'woocommerce-advanced-free-shipping' ),
|
113 |
+
),
|
114 |
+
__( 'User Details', 'woocommerce-advanced-free-shipping' ) => array(
|
115 |
+
'zipcode' => __( 'Zipcode', 'woocommerce-advanced-free-shipping' ),
|
116 |
+
'city' => __( 'City', 'woocommerce-advanced-free-shipping' ),
|
117 |
+
'state' => __( 'State', 'woocommerce-advanced-free-shipping' ),
|
118 |
+
'country' => __( 'Country', 'woocommerce-advanced-free-shipping' ),
|
119 |
+
'role' => __( 'User role', 'woocommerce-advanced-free-shipping' ),
|
120 |
+
),
|
121 |
+
__( 'Product', 'woocommerce-advanced-free-shipping' ) => array(
|
122 |
+
'width' => __( 'Width', 'woocommerce-advanced-free-shipping' ),
|
123 |
+
'height' => __( 'Height', 'woocommerce-advanced-free-shipping' ),
|
124 |
+
'length' => __( 'Length', 'woocommerce-advanced-free-shipping' ),
|
125 |
+
'stock' => __( 'Stock', 'woocommerce-advanced-free-shipping' ),
|
126 |
+
'stock_status' => __( 'Stock status', 'woocommerce-advanced-free-shipping' ),
|
127 |
+
'category' => __( 'Category', 'woocommerce-advanced-free-shipping' ),
|
128 |
+
),
|
129 |
+
);
|
130 |
+
$conditions = apply_filters( 'wafs_conditions', $conditions );
|
131 |
+
|
132 |
+
return $conditions;
|
133 |
+
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Get available operators.
|
139 |
+
*
|
140 |
+
* Get a list with the available operators for the conditions.
|
141 |
+
*
|
142 |
+
* @since 1.1.6
|
143 |
+
*
|
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 |
+
|
161 |
+
/**
|
162 |
+
* Get value field args.
|
163 |
+
*
|
164 |
+
* Get the value field args that are condition dependent. This usually includes
|
165 |
+
* type, class and placeholder.
|
166 |
+
*
|
167 |
+
* @since 1.1.6
|
168 |
+
*
|
169 |
+
* @return array
|
170 |
+
*/
|
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 |
+
foreach ( WC()->countries->states as $country => $states ) :
|
235 |
+
|
236 |
+
if ( empty( $states ) ) continue; // Don't show country if it has no states
|
237 |
+
if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries
|
238 |
+
|
239 |
+
$country_states = array();
|
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 |
+
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Get description.
|
324 |
+
*
|
325 |
+
* Return the description related to this condition.
|
326 |
+
*
|
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 |
+
|
350 |
+
}
|
includes/admin/settings/conditions/class-wafs-condition.php
DELETED
@@ -1,227 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Class WAFS_Condition.
|
4 |
-
*
|
5 |
-
* Create a condition rule.
|
6 |
-
*
|
7 |
-
* @class WAFS_Condition
|
8 |
-
* @author Jeroen Sormani
|
9 |
-
* @package WooCommerce Advanced Free Shipping
|
10 |
-
* @version 1.0.0
|
11 |
-
*/
|
12 |
-
|
13 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
14 |
-
|
15 |
-
class WAFS_Condition {
|
16 |
-
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Condition.
|
20 |
-
*
|
21 |
-
* @since 1.0.0
|
22 |
-
* @access public
|
23 |
-
* @var string $condition Condition slug.
|
24 |
-
*/
|
25 |
-
public $condition;
|
26 |
-
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Operator.
|
30 |
-
*
|
31 |
-
* @since 1.0.0
|
32 |
-
* @access public
|
33 |
-
* @var string $operaor operator slug.
|
34 |
-
*/
|
35 |
-
public $operator;
|
36 |
-
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Value.
|
40 |
-
*
|
41 |
-
* @since 1.0.0
|
42 |
-
* @access public
|
43 |
-
* @var string $value Condition value.
|
44 |
-
*/
|
45 |
-
public $value;
|
46 |
-
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Group ID.
|
50 |
-
*
|
51 |
-
* @since 1.0.0
|
52 |
-
* @access public
|
53 |
-
* @var string $group Condition grou ID.
|
54 |
-
*/
|
55 |
-
public $group;
|
56 |
-
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Condition id.
|
60 |
-
*
|
61 |
-
* @since 1.0.0
|
62 |
-
* @access public
|
63 |
-
* @var string $id Condition ID.
|
64 |
-
*/
|
65 |
-
public $id;
|
66 |
-
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Constructor.
|
70 |
-
*
|
71 |
-
* @since 1.0.0
|
72 |
-
*/
|
73 |
-
public function __construct( $id = null, $group = 0, $condition = null, $operator = null, $value = null ) {
|
74 |
-
|
75 |
-
$this->id = $id;
|
76 |
-
$this->group = $group;
|
77 |
-
$this->condition = $condition;
|
78 |
-
$this->operator = $operator;
|
79 |
-
$this->value = $value;
|
80 |
-
|
81 |
-
if ( ! $id ) {
|
82 |
-
$this->id = rand();
|
83 |
-
}
|
84 |
-
|
85 |
-
$this->wafs_create_object();
|
86 |
-
|
87 |
-
}
|
88 |
-
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Condition rule.
|
92 |
-
*
|
93 |
-
* Create an condition rule object.
|
94 |
-
*
|
95 |
-
* @since 1.0.0
|
96 |
-
*/
|
97 |
-
public function wafs_create_object() {
|
98 |
-
|
99 |
-
?><div class='wafs-condition-wrap'><?php
|
100 |
-
|
101 |
-
do_action( 'wafs_before_condition', $this );
|
102 |
-
|
103 |
-
$this->wafs_condition_conditions();
|
104 |
-
$this->wafs_condition_operator();
|
105 |
-
$this->wafs_condition_values();
|
106 |
-
|
107 |
-
$this->wafs_add_condition_button();
|
108 |
-
$this->wafs_remove_condition_button();
|
109 |
-
|
110 |
-
$this->wafs_condition_description();
|
111 |
-
|
112 |
-
do_action( 'wafs_after_condition', $this );
|
113 |
-
|
114 |
-
?></div><?php
|
115 |
-
|
116 |
-
}
|
117 |
-
|
118 |
-
|
119 |
-
/**
|
120 |
-
* Condition dropdown.
|
121 |
-
*
|
122 |
-
* Render and load condition dropdown.
|
123 |
-
*
|
124 |
-
* @since 1.0.0
|
125 |
-
*/
|
126 |
-
public function wafs_condition_conditions() {
|
127 |
-
|
128 |
-
wafs_condition_conditions( $this->id, $this->group, $this->condition );
|
129 |
-
|
130 |
-
}
|
131 |
-
|
132 |
-
|
133 |
-
/**
|
134 |
-
* Operator dropdown.
|
135 |
-
*
|
136 |
-
* Render and load operator dropdown.
|
137 |
-
*
|
138 |
-
* @since 1.0.0
|
139 |
-
*/
|
140 |
-
public function wafs_condition_operator() {
|
141 |
-
|
142 |
-
wafs_condition_operator( $this->id, $this->group, $this->operator );
|
143 |
-
|
144 |
-
}
|
145 |
-
|
146 |
-
|
147 |
-
/**
|
148 |
-
* Value dropdown.
|
149 |
-
*
|
150 |
-
* Render and load value dropdown.
|
151 |
-
*
|
152 |
-
* @since 1.0.0
|
153 |
-
*/
|
154 |
-
public function wafs_condition_values() {
|
155 |
-
|
156 |
-
wafs_condition_values( $this->id, $this->group, $this->condition, $this->value );
|
157 |
-
|
158 |
-
}
|
159 |
-
|
160 |
-
|
161 |
-
/**
|
162 |
-
* Add button.
|
163 |
-
*
|
164 |
-
* Display a add button at the end of the condition rule.
|
165 |
-
*
|
166 |
-
* @since 1.0.0
|
167 |
-
*/
|
168 |
-
public function wafs_add_condition_button() {
|
169 |
-
|
170 |
-
?>
|
171 |
-
<a class='button condition-add' data-group='<?php echo absint( $this->group ); ?>' href='javascript:void(0);'>+</a>
|
172 |
-
<?php
|
173 |
-
|
174 |
-
}
|
175 |
-
|
176 |
-
|
177 |
-
/**
|
178 |
-
* Remove button.
|
179 |
-
*
|
180 |
-
* Display aa remove button at the end of the condition rule.
|
181 |
-
*
|
182 |
-
* @since 1.0.0
|
183 |
-
*/
|
184 |
-
public function wafs_remove_condition_button() {
|
185 |
-
|
186 |
-
?>
|
187 |
-
<a class='button condition-delete' href='javascript:void(0);'>-</a>
|
188 |
-
<?php
|
189 |
-
|
190 |
-
}
|
191 |
-
|
192 |
-
|
193 |
-
/**
|
194 |
-
* Description.
|
195 |
-
*
|
196 |
-
* Display an description at the end of the condition rule.
|
197 |
-
*
|
198 |
-
* @since 1.0.0
|
199 |
-
*/
|
200 |
-
public function wafs_condition_description() {
|
201 |
-
|
202 |
-
wafs_condition_description( $this->condition );
|
203 |
-
|
204 |
-
}
|
205 |
-
|
206 |
-
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* Load condition keys dropdown.
|
211 |
-
*/
|
212 |
-
require_once plugin_dir_path( __FILE__ ) . 'condition-conditions.php';
|
213 |
-
|
214 |
-
/**
|
215 |
-
* Load condition operator dropdown.
|
216 |
-
*/
|
217 |
-
require_once plugin_dir_path( __FILE__ ) . 'condition-operators.php';
|
218 |
-
|
219 |
-
/**
|
220 |
-
* Load condition value dropdown.
|
221 |
-
*/
|
222 |
-
require_once plugin_dir_path( __FILE__ ) . 'condition-values.php';
|
223 |
-
|
224 |
-
/**
|
225 |
-
* Load condition descriptions.
|
226 |
-
*/
|
227 |
-
require_once plugin_dir_path( __FILE__ ) . 'condition-descriptions.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/admin/settings/conditions/condition-conditions.php
DELETED
@@ -1,68 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Create condition dropdown.
|
6 |
-
*
|
7 |
-
* Set all conditions and create dropdown for it.
|
8 |
-
*
|
9 |
-
* @since 1.0.0
|
10 |
-
*
|
11 |
-
* @param mixed $id Throw in the condition ID.
|
12 |
-
* @param midex $group Condition group ID.
|
13 |
-
* @param string $current_value Current chosen slug.
|
14 |
-
*/
|
15 |
-
function wafs_condition_conditions( $id, $group = 0, $current_value = 'subtotal' ) {
|
16 |
-
|
17 |
-
$conditions = array(
|
18 |
-
__( 'Cart', 'woocommerce-advanced-free-shipping' ) => array(
|
19 |
-
'subtotal' => __( 'Subtotal', 'woocommerce-advanced-free-shipping' ),
|
20 |
-
'subtotal_ex_tax' => __( 'Subtotal ex. taxes', 'woocommerce-advanced-free-shipping' ),
|
21 |
-
'tax' => __( 'Tax', 'woocommerce-advanced-free-shipping' ),
|
22 |
-
'quantity' => __( 'Quantity', 'woocommerce-advanced-free-shipping' ),
|
23 |
-
'contains_product' => __( 'Contains product', 'woocommerce-advanced-free-shipping' ),
|
24 |
-
'coupon' => __( 'Coupon', 'woocommerce-advanced-free-shipping' ),
|
25 |
-
'weight' => __( 'Weight', 'woocommerce-advanced-free-shipping' ),
|
26 |
-
'contains_shipping_class' => __( 'Contains shipping class', 'woocommerce-advanced-free-shipping' ),
|
27 |
-
),
|
28 |
-
__( 'User Details', 'woocommerce-advanced-free-shipping' ) => array(
|
29 |
-
'zipcode' => __( 'Zipcode', 'woocommerce-advanced-free-shipping' ),
|
30 |
-
'city' => __( 'City', 'woocommerce-advanced-free-shipping' ),
|
31 |
-
'state' => __( 'State', 'woocommerce-advanced-free-shipping' ),
|
32 |
-
'country' => __( 'Country', 'woocommerce-advanced-free-shipping' ),
|
33 |
-
'role' => __( 'User role', 'woocommerce-advanced-free-shipping' ),
|
34 |
-
),
|
35 |
-
__( 'Product', 'woocommerce-advanced-free-shipping' ) => array(
|
36 |
-
'width' => __( 'Width', 'woocommerce-advanced-free-shipping' ),
|
37 |
-
'height' => __( 'Height', 'woocommerce-advanced-free-shipping' ),
|
38 |
-
'length' => __( 'Length', 'woocommerce-advanced-free-shipping' ),
|
39 |
-
'stock' => __( 'Stock', 'woocommerce-advanced-free-shipping' ),
|
40 |
-
'stock_status' => __( 'Stock status', 'woocommerce-advanced-free-shipping' ),
|
41 |
-
'category' => __( 'Category', 'woocommerce-advanced-free-shipping' ),
|
42 |
-
),
|
43 |
-
);
|
44 |
-
|
45 |
-
$conditions = apply_filters( 'wafs_conditions', $conditions );
|
46 |
-
|
47 |
-
?><span class='wafs-condition-wrap wafs-condition-wrap-<?php echo absint( $id ); ?>'>
|
48 |
-
|
49 |
-
<select class='wafs-condition' data-group='<?php echo absint( $group ); ?>' data-id='<?php echo absint( $id ); ?>'
|
50 |
-
name='_wafs_shipping_method_conditions[<?php echo absint( $group ); ?>][<?php echo absint( $id ); ?>][condition]'><?php
|
51 |
-
|
52 |
-
foreach ( $conditions as $option_group => $values ) :
|
53 |
-
|
54 |
-
?><optgroup label='<?php echo esc_attr( $option_group ); ?>'><?php
|
55 |
-
|
56 |
-
foreach ( $values as $key => $value ) :
|
57 |
-
?><option value='<?php echo esc_attr( $key ); ?>' <?php selected( $key, $current_value ); ?>><?php echo esc_html( $value ); ?></option><?php
|
58 |
-
endforeach;
|
59 |
-
|
60 |
-
?></optgroup><?php
|
61 |
-
|
62 |
-
endforeach;
|
63 |
-
|
64 |
-
?></select>
|
65 |
-
|
66 |
-
</span><?php
|
67 |
-
|
68 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/admin/settings/conditions/condition-descriptions.php
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Descriptions.
|
6 |
-
*
|
7 |
-
* Display a description icon + tooltip on hover.
|
8 |
-
*
|
9 |
-
* @since 1.0.0
|
10 |
-
*
|
11 |
-
* @param string $condition Condition to show description for.
|
12 |
-
*/
|
13 |
-
function wafs_condition_description( $condition ) {
|
14 |
-
|
15 |
-
$descriptions = array(
|
16 |
-
'state' => __( 'States must be installed in WC.', 'woocommerce-advanced-free-shipping' ),
|
17 |
-
'weight' => __( 'Weight calculated on all the cart contents', 'woocommerce-advanced-free-shipping' ),
|
18 |
-
'length' => __( 'Compared to lengthiest product in cart', 'woocommerce-advanced-free-shipping' ),
|
19 |
-
'width' => __( 'Compared to widest product in cart', 'woocommerce-advanced-free-shipping' ),
|
20 |
-
'height' => __( 'Compared to highest product in cart', 'woocommerce-advanced-free-shipping' ),
|
21 |
-
'stock_status' => __( 'All products in cart must match stock status', 'woocommerce-advanced-free-shipping' ),
|
22 |
-
'category' => __( 'All products in cart must match category', 'woocommerce-advanced-free-shipping' ),
|
23 |
-
'contains_product' => __( 'Cart must contain one of this product', 'woocommerce-advanced-free-shipping' ),
|
24 |
-
'contains_shipping_class' => __( 'Cart must contain at least one product with the selected shipping class', 'woocommerce-advanced-free-shipping' ),
|
25 |
-
);
|
26 |
-
|
27 |
-
$descriptions = apply_filters( 'wafs_descriptions', $descriptions );
|
28 |
-
|
29 |
-
// Display description
|
30 |
-
if ( ! isset( $descriptions[ $condition ] ) ) :
|
31 |
-
?><span class='wafs-description no-description'></span><?php
|
32 |
-
return;
|
33 |
-
endif;
|
34 |
-
|
35 |
-
?><span class='wafs-description <?php echo sanitize_html_class( $condition ); ?>-description'>
|
36 |
-
|
37 |
-
<div class='description'>
|
38 |
-
|
39 |
-
<img class='wafs_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' />
|
40 |
-
|
41 |
-
<div class='wafs_desc'><?php
|
42 |
-
echo esc_html( $descriptions[ $condition ] );
|
43 |
-
?></div>
|
44 |
-
|
45 |
-
</div>
|
46 |
-
|
47 |
-
</span><?php
|
48 |
-
|
49 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/admin/settings/conditions/condition-operators.php
DELETED
@@ -1,40 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Create operator dropdown.
|
6 |
-
*
|
7 |
-
* Set all operators and create dropdown for it.
|
8 |
-
*
|
9 |
-
* @since 1.0.0
|
10 |
-
*
|
11 |
-
* @param int $id Throw in the condition ID.
|
12 |
-
* @param int $group Condition group ID.
|
13 |
-
* @param string $current_value Current chosen slug.
|
14 |
-
*/
|
15 |
-
function wafs_condition_operator( $id, $group = 0, $current_value = '==' ) {
|
16 |
-
|
17 |
-
$operators = array(
|
18 |
-
'==' => __( 'Equal to', 'woocommerce-advanced-free-shipping' ),
|
19 |
-
'!=' => __( 'Not equal to', 'woocommerce-advanced-free-shipping' ),
|
20 |
-
'>=' => __( 'Greater or equal to', 'woocommerce-advanced-free-shipping' ),
|
21 |
-
'<=' => __( 'Less or equal to ', 'woocommerce-advanced-free-shipping' ),
|
22 |
-
);
|
23 |
-
|
24 |
-
$operators = apply_filters( 'wafs_operators', $operators );
|
25 |
-
|
26 |
-
?><span class='wafs-operator-wrap wafs-operator-wrap-<?php echo absint( $id ); ?>'>
|
27 |
-
|
28 |
-
<select id='' class='wafs-operator' name='_wafs_shipping_method_conditions[<?php echo absint( $group ); ?>][<?php echo absint( $id ); ?>][operator]'>
|
29 |
-
|
30 |
-
<?php foreach ( $operators as $key => $value ) :
|
31 |
-
|
32 |
-
?><option value='<?php echo esc_attr( $key ); ?>' <?php selected( $key, $current_value ); ?>><?php echo esc_html( $value ); ?></option><?php
|
33 |
-
|
34 |
-
endforeach; ?>
|
35 |
-
|
36 |
-
</select>
|
37 |
-
|
38 |
-
</span><?php
|
39 |
-
|
40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/admin/settings/conditions/condition-values.php
DELETED
@@ -1,250 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Create value input.
|
6 |
-
*
|
7 |
-
* Set all value and create an input field for it.
|
8 |
-
*
|
9 |
-
* @since 1.0.0
|
10 |
-
*
|
11 |
-
* @param int $id Throw in the condition ID.
|
12 |
-
* @param int $group Condition group ID.
|
13 |
-
* @param string $condition Condition where the value input is used for.
|
14 |
-
* @param string $current_value Current chosen slug.
|
15 |
-
*/
|
16 |
-
function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $current_value = '' ) {
|
17 |
-
|
18 |
-
// Defaults
|
19 |
-
$values = array( 'placeholder' => '', 'min' => '', 'max' => '', 'field' => 'text', 'options' => array() );
|
20 |
-
|
21 |
-
switch ( $condition ) :
|
22 |
-
|
23 |
-
default:
|
24 |
-
case 'subtotal' :
|
25 |
-
|
26 |
-
$values['field'] = 'number';
|
27 |
-
|
28 |
-
break;
|
29 |
-
|
30 |
-
case 'subtotal_ex_tax' :
|
31 |
-
|
32 |
-
$values['field'] = 'number';
|
33 |
-
|
34 |
-
break;
|
35 |
-
|
36 |
-
case 'tax' :
|
37 |
-
|
38 |
-
$values['field'] = 'number';
|
39 |
-
|
40 |
-
break;
|
41 |
-
|
42 |
-
case 'quantity' :
|
43 |
-
|
44 |
-
$values['field'] = 'number';
|
45 |
-
|
46 |
-
break;
|
47 |
-
|
48 |
-
case 'contains_product' :
|
49 |
-
|
50 |
-
$values['field'] = 'select';
|
51 |
-
|
52 |
-
$products = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'product', 'order' => 'asc', 'orderby' => 'title' ) );
|
53 |
-
foreach ( $products as $product ) :
|
54 |
-
$values['options'][ $product->ID ] = $product->post_title;
|
55 |
-
endforeach;
|
56 |
-
|
57 |
-
break;
|
58 |
-
|
59 |
-
case 'coupon' :
|
60 |
-
|
61 |
-
$values['field'] = 'text';
|
62 |
-
|
63 |
-
break;
|
64 |
-
|
65 |
-
case 'weight' :
|
66 |
-
|
67 |
-
$values['field'] = 'text';
|
68 |
-
|
69 |
-
break;
|
70 |
-
|
71 |
-
case 'contains_shipping_class' :
|
72 |
-
|
73 |
-
$values['field'] = 'select';
|
74 |
-
$values['options'][''] = __( 'No shipping class', 'woocommerce' );
|
75 |
-
|
76 |
-
// Get all shipping classes
|
77 |
-
foreach ( get_terms( 'product_shipping_class', array( 'hide_empty' => false ) ) as $shipping_class ) :
|
78 |
-
$values['options'][ $shipping_class->slug ] = $shipping_class->name;
|
79 |
-
endforeach;
|
80 |
-
|
81 |
-
break;
|
82 |
-
|
83 |
-
/**
|
84 |
-
* User details
|
85 |
-
*/
|
86 |
-
|
87 |
-
case 'zipcode' :
|
88 |
-
|
89 |
-
$values['field'] = 'text';
|
90 |
-
|
91 |
-
break;
|
92 |
-
|
93 |
-
case 'city' :
|
94 |
-
|
95 |
-
$values['field'] = 'text';
|
96 |
-
|
97 |
-
break;
|
98 |
-
|
99 |
-
case 'state' :
|
100 |
-
|
101 |
-
$values['field'] = 'select';
|
102 |
-
|
103 |
-
foreach ( WC()->countries->states as $country => $states ) :
|
104 |
-
|
105 |
-
if ( empty( $states ) ) continue; // Don't show country if it has no states
|
106 |
-
if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries
|
107 |
-
|
108 |
-
foreach ( $states as $state_key => $state ) :
|
109 |
-
$country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state;
|
110 |
-
endforeach;
|
111 |
-
|
112 |
-
$values['options'] = $country_states;
|
113 |
-
|
114 |
-
endforeach;
|
115 |
-
|
116 |
-
break;
|
117 |
-
|
118 |
-
case 'country' :
|
119 |
-
|
120 |
-
$values['field'] = 'select';
|
121 |
-
$values['options'] = WC()->countries->get_allowed_countries();
|
122 |
-
|
123 |
-
break;
|
124 |
-
|
125 |
-
case 'role' :
|
126 |
-
|
127 |
-
$values['field'] = 'select';
|
128 |
-
$roles = array_keys( get_editable_roles() );
|
129 |
-
$values['options'] = array_combine( $roles, $roles );
|
130 |
-
|
131 |
-
break;
|
132 |
-
|
133 |
-
/**
|
134 |
-
* Product
|
135 |
-
*/
|
136 |
-
|
137 |
-
case 'width' :
|
138 |
-
|
139 |
-
$values['field'] = 'text';
|
140 |
-
|
141 |
-
break;
|
142 |
-
|
143 |
-
|
144 |
-
case 'height' :
|
145 |
-
|
146 |
-
$values['field'] = 'text';
|
147 |
-
|
148 |
-
break;
|
149 |
-
|
150 |
-
|
151 |
-
case 'length' :
|
152 |
-
|
153 |
-
$values['field'] = 'text';
|
154 |
-
|
155 |
-
break;
|
156 |
-
|
157 |
-
case 'stock' :
|
158 |
-
|
159 |
-
$values['field'] = 'text';
|
160 |
-
|
161 |
-
break;
|
162 |
-
|
163 |
-
case 'stock_status' :
|
164 |
-
|
165 |
-
$values['field'] = 'select';
|
166 |
-
$values['options'] = array(
|
167 |
-
'instock' => __( 'In stock', 'woocommerce-advanced-free-shipping' ),
|
168 |
-
'outofstock' => __( 'Out of stock', 'woocommerce-advanced-free-shipping' ),
|
169 |
-
);
|
170 |
-
|
171 |
-
break;
|
172 |
-
|
173 |
-
case 'category' :
|
174 |
-
|
175 |
-
$values['field'] = 'select';
|
176 |
-
|
177 |
-
$categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
|
178 |
-
foreach ( $categories as $category ) :
|
179 |
-
$values['options'][ $category->slug ] = $category->name;
|
180 |
-
endforeach;
|
181 |
-
|
182 |
-
break;
|
183 |
-
|
184 |
-
|
185 |
-
endswitch;
|
186 |
-
|
187 |
-
$values = apply_filters( 'wafs_values', $values, $condition );
|
188 |
-
|
189 |
-
?><span class='wafs-value-wrap wafs-value-wrap-<?php echo absint( $id ); ?>'><?php
|
190 |
-
|
191 |
-
switch ( $values['field'] ) :
|
192 |
-
|
193 |
-
case 'text' :
|
194 |
-
|
195 |
-
?><input type='text' class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo absint( $group ); ?>][<?php echo absint( $id ); ?>][value]'
|
196 |
-
placeholder='<?php echo esc_attr( @$values['placeholder'] ); ?>' value='<?php echo esc_attr( $current_value ); ?>'><?php
|
197 |
-
|
198 |
-
break;
|
199 |
-
|
200 |
-
case 'number' :
|
201 |
-
|
202 |
-
?><input type='text' class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo absint( $group ); ?>][<?php echo absint( $id ); ?>][value]'
|
203 |
-
min='<?php echo esc_attr( @$values['min'] ); ?>' max='<?php echo esc_attr( @$values['max'] ); ?>' placeholder='<?php echo esc_attr( @$values['placeholder'] ); ?>'
|
204 |
-
value='<?php echo esc_attr( $current_value ); ?>'><?php
|
205 |
-
|
206 |
-
break;
|
207 |
-
|
208 |
-
case 'select' :
|
209 |
-
|
210 |
-
// Backwards compatibility for extensions
|
211 |
-
if ( isset( $values['values'] ) ) {
|
212 |
-
@array_merge( $values['options'], $values['values'] );
|
213 |
-
}
|
214 |
-
?><select class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo absint( $group ); ?>][<?php echo absint( $id ); ?>][value]'>
|
215 |
-
|
216 |
-
<option <?php selected( '', $current_value ); ?>><?php _e( 'Select option', 'woocommerce-advanced-free-shipping' ); ?></option><?php
|
217 |
-
foreach ( $values['options'] as $key => $value ) :
|
218 |
-
|
219 |
-
if ( ! is_array( $value ) ) :
|
220 |
-
?><option value='<?php echo esc_attr( $key ); ?>' <?php selected( $key, $current_value ); ?>><?php echo esc_html( $value ); ?></option><?php
|
221 |
-
else :
|
222 |
-
?><optgroup label='<?php echo $key; ?>'><?php
|
223 |
-
foreach ( $value as $k => $v ) :
|
224 |
-
?><option value='<?php echo esc_attr( $k ); ?>' <?php selected( $k, $current_value ); ?>><?php echo esc_html( $v ); ?></option><?php
|
225 |
-
endforeach;
|
226 |
-
?></optgroup><?php
|
227 |
-
|
228 |
-
endif;
|
229 |
-
|
230 |
-
endforeach;
|
231 |
-
|
232 |
-
if ( empty( $values['options'] ) ) :
|
233 |
-
?><option readonly disabled><?php
|
234 |
-
_e( 'There are no options available', 'woocommerce-advanced-free-shipping' );
|
235 |
-
?></option><?php
|
236 |
-
endif;
|
237 |
-
|
238 |
-
?></select><?php
|
239 |
-
|
240 |
-
break;
|
241 |
-
|
242 |
-
default :
|
243 |
-
do_action( 'wafs_condition_value_field_type_' . $values['field'], $values );
|
244 |
-
break;
|
245 |
-
|
246 |
-
endswitch;
|
247 |
-
|
248 |
-
?></span><?php
|
249 |
-
|
250 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/admin/settings/meta-box-conditions.php
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WAFS meta box conditions.
|
4 |
-
*
|
5 |
-
* Display the shipping conditions in the meta box.
|
6 |
-
*
|
7 |
-
* @author Jeroen Sormani
|
8 |
-
* @package WooCommerce Advanced Free Shipping
|
9 |
-
* @version 1.0.0
|
10 |
-
*/
|
11 |
-
|
12 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
13 |
-
|
14 |
-
wp_nonce_field( 'wafs_conditions_meta_box', 'wafs_conditions_meta_box_nonce' );
|
15 |
-
|
16 |
-
global $post;
|
17 |
-
$conditions = get_post_meta( $post->ID, '_wafs_shipping_method_conditions', true );
|
18 |
-
|
19 |
-
?><div class='wafs wafs_conditions wafs_meta_box wafs_conditions_meta_box'>
|
20 |
-
|
21 |
-
<p><strong><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
|
22 |
-
|
23 |
-
if ( ! empty( $conditions ) ) :
|
24 |
-
|
25 |
-
foreach ( $conditions as $condition_group => $conditions ) :
|
26 |
-
|
27 |
-
?><div class='condition-group condition-group-<?php echo absint( $condition_group ); ?>' data-group='<?php echo absint( $condition_group ); ?>'>
|
28 |
-
|
29 |
-
<p class='or_match'>
|
30 |
-
<?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' );?>
|
31 |
-
</p><?php
|
32 |
-
|
33 |
-
foreach ( $conditions as $condition_id => $condition ) :
|
34 |
-
|
35 |
-
new Wafs_Condition( $condition_id, $condition_group, $condition['condition'], $condition['operator'], $condition['value'] );
|
36 |
-
|
37 |
-
endforeach;
|
38 |
-
|
39 |
-
?></div>
|
40 |
-
|
41 |
-
<p><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
|
42 |
-
|
43 |
-
endforeach;
|
44 |
-
|
45 |
-
else :
|
46 |
-
|
47 |
-
?><div class='condition-group condition-group-0' data-group='0'><?php
|
48 |
-
new Wafs_Condition();
|
49 |
-
?></div><?php
|
50 |
-
|
51 |
-
endif;
|
52 |
-
|
53 |
-
?></div>
|
54 |
-
|
55 |
-
<a class='button condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'woocommerce-advanced-free-shipping' ); ?></a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/admin/views/conditions-table.php
CHANGED
@@ -11,16 +11,15 @@
|
|
11 |
|
12 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
13 |
|
14 |
-
$
|
15 |
|
16 |
?><tr valign="top">
|
17 |
<th scope="row" class="titledesc">
|
18 |
-
<?php _e( '
|
19 |
-
<!-- <small>Read more</small> -->
|
20 |
</th>
|
21 |
<td class="forminp" id="<?php echo $this->id; ?>_shipping_methods">
|
22 |
|
23 |
-
<table class='wp-list-table
|
24 |
<thead>
|
25 |
<tr>
|
26 |
<th style='padding-left: 10px;'><?php _e( 'Title', 'woocommerce-advanced-free-shipping' ); ?></th>
|
@@ -31,28 +30,29 @@ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' =>
|
|
31 |
<tbody><?php
|
32 |
|
33 |
$i = 0;
|
34 |
-
foreach ( $
|
35 |
|
36 |
-
$method_details = get_post_meta( $
|
37 |
-
$conditions = get_post_meta( $
|
38 |
$alt = ( $i++ ) % 2 == 0 ? 'alternate' : '';
|
39 |
|
40 |
?><tr class='<?php echo $alt; ?>'>
|
41 |
<td>
|
42 |
<strong>
|
43 |
-
<a href='<?php echo get_edit_post_link( $
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
47 |
<div class='row-actions'>
|
48 |
<span class='edit'>
|
49 |
-
<a href='<?php echo get_edit_post_link( $
|
50 |
<?php _e( 'Edit', 'woocommerce-advanced-free-shipping' ); ?>
|
51 |
</a>
|
52 |
|
|
53 |
</span>
|
54 |
<span class='trash'>
|
55 |
-
<a href='<?php echo get_delete_post_link( $
|
56 |
_e( 'Delete', 'woocommerce-advanced-free-shipping' );
|
57 |
?></a>
|
58 |
</span>
|
@@ -60,23 +60,21 @@ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' =>
|
|
60 |
</td>
|
61 |
<td><?php echo empty( $method_details['shipping_title'] ) ? __( 'Free Shipping', 'woocommerce-advanced-free-shipping' ) : esc_html( $method_details['shipping_title'] ); ?></td>
|
62 |
<td><?php echo count( $conditions ); ?></td>
|
63 |
-
</td>
|
64 |
</tr><?php
|
65 |
|
66 |
endforeach;
|
67 |
|
68 |
-
if ( empty( $
|
69 |
-
|
70 |
?><tr>
|
71 |
-
<td colspan='2'><?php _e( 'There are no Free Shipping
|
72 |
</tr><?php
|
73 |
-
|
74 |
|
75 |
?></tbody>
|
76 |
<tfoot>
|
77 |
<tr>
|
78 |
<th colspan='4' style='padding-left: 10px;'>
|
79 |
-
<a href='<?php echo admin_url( 'post-new.php?post_type=wafs' ); ?>' class='add button'><?php _e( 'Add Free Shipping
|
80 |
</th>
|
81 |
</tr>
|
82 |
</tfoot>
|
11 |
|
12 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
13 |
|
14 |
+
$shipping_rates = wafs_get_rates( array( 'post_status' => array( 'draft', 'publish' ) ) );
|
15 |
|
16 |
?><tr valign="top">
|
17 |
<th scope="row" class="titledesc">
|
18 |
+
<?php _e( 'Free shipping rates', 'woocommerce-advanced-free-shipping' ); ?><br />
|
|
|
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>
|
30 |
<tbody><?php
|
31 |
|
32 |
$i = 0;
|
33 |
+
foreach ( $shipping_rates as $post ) :
|
34 |
|
35 |
+
$method_details = get_post_meta( $post->ID, '_wafs_shipping_method', true );
|
36 |
+
$conditions = get_post_meta( $post->ID, '_wafs_shipping_method_conditions', true );
|
37 |
$alt = ( $i++ ) % 2 == 0 ? 'alternate' : '';
|
38 |
|
39 |
?><tr class='<?php echo $alt; ?>'>
|
40 |
<td>
|
41 |
<strong>
|
42 |
+
<a href='<?php echo get_edit_post_link( $post->ID ); ?>' class='row-title' title='<?php _e( 'Edit Method', 'woocommerce-advanced-fees' ); ?>'><?php
|
43 |
+
echo _draft_or_post_title( $post->ID );
|
44 |
+
?></a><?php
|
45 |
+
_post_states( $post );
|
46 |
+
?></strong>
|
47 |
<div class='row-actions'>
|
48 |
<span class='edit'>
|
49 |
+
<a href='<?php echo get_edit_post_link( $post->ID ); ?>' title='<?php _e( 'Edit Method', 'woocommerce-advanced-free-shipping' ); ?>'>
|
50 |
<?php _e( 'Edit', 'woocommerce-advanced-free-shipping' ); ?>
|
51 |
</a>
|
52 |
|
|
53 |
</span>
|
54 |
<span class='trash'>
|
55 |
+
<a href='<?php echo get_delete_post_link( $post->ID ); ?>' title='<?php _e( 'Delete Method', 'woocommerce-advanced-free-shipping' ); ?>'><?php
|
56 |
_e( 'Delete', 'woocommerce-advanced-free-shipping' );
|
57 |
?></a>
|
58 |
</span>
|
60 |
</td>
|
61 |
<td><?php echo empty( $method_details['shipping_title'] ) ? __( 'Free Shipping', 'woocommerce-advanced-free-shipping' ) : esc_html( $method_details['shipping_title'] ); ?></td>
|
62 |
<td><?php echo count( $conditions ); ?></td>
|
|
|
63 |
</tr><?php
|
64 |
|
65 |
endforeach;
|
66 |
|
67 |
+
if ( empty( $shipping_rates ) ) :
|
|
|
68 |
?><tr>
|
69 |
+
<td colspan='2'><?php _e( 'There are no Free Shipping rates. Yet...', 'woocommerce-advanced-free-shipping' ); ?></td>
|
70 |
</tr><?php
|
71 |
+
endif;
|
72 |
|
73 |
?></tbody>
|
74 |
<tfoot>
|
75 |
<tr>
|
76 |
<th colspan='4' style='padding-left: 10px;'>
|
77 |
+
<a href='<?php echo admin_url( 'post-new.php?post_type=wafs' ); ?>' class='add button'><?php _e( 'Add Free Shipping rate', 'woocommerce-advanced-free-shipping' ); ?></a>
|
78 |
</th>
|
79 |
</tr>
|
80 |
</tfoot>
|
includes/admin/views/html-condition-row.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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',
|
11 |
+
'name' => 'conditions[' . absint( $wp_condition->group ) . '][' . absint( $wp_condition->id ) . '][condition]',
|
12 |
+
'class' => array( 'wpc-condition' ),
|
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 );
|
21 |
+
|
22 |
+
?></span>
|
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',
|
30 |
+
'name' => 'conditions[' . absint( $wp_condition->group ) . '][' . absint( $wp_condition->id ) . '][operator]',
|
31 |
+
'class' => array( 'wpc-operator' ),
|
32 |
+
'options' => $wp_condition->get_operators(),
|
33 |
+
'value' => $wp_condition->operator,
|
34 |
+
);
|
35 |
+
wpc_html_field( $operator_field_args );
|
36 |
+
|
37 |
+
?></span>
|
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>
|
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>
|
includes/admin/views/meta-box-conditions.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
global $post;
|
5 |
+
$condition_groups = get_post_meta( $post->ID, '_wafs_shipping_method_conditions', true );
|
6 |
+
|
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>
|
includes/admin/{settings → views}/meta-box-settings.php
RENAMED
@@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
14 |
wp_nonce_field( 'wafs_settings_meta_box', 'wafs_settings_meta_box_nonce' );
|
15 |
|
16 |
global $post;
|
17 |
-
$settings
|
18 |
$settings['shipping_title'] = ! empty( $settings['shipping_title'] ) ? $settings['shipping_title'] : '';
|
19 |
|
20 |
?><div class='wafs wafs_settings wafs_meta_box wafs_settings_meta_box'>
|
@@ -22,8 +22,13 @@ $settings['shipping_title'] = ! empty( $settings['shipping_title'] ) ? $settings
|
|
22 |
<p class='wafs-option'>
|
23 |
|
24 |
<label for='shipping_title'><?php _e( 'Shipping title', 'woocommerce-advanced-free-shipping' ); ?></label>
|
25 |
-
<input
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
</p>
|
29 |
|
14 |
wp_nonce_field( 'wafs_settings_meta_box', 'wafs_settings_meta_box_nonce' );
|
15 |
|
16 |
global $post;
|
17 |
+
$settings = get_post_meta( $post->ID, '_wafs_shipping_method', true );
|
18 |
$settings['shipping_title'] = ! empty( $settings['shipping_title'] ) ? $settings['shipping_title'] : '';
|
19 |
|
20 |
?><div class='wafs wafs_settings wafs_meta_box wafs_settings_meta_box'>
|
22 |
<p class='wafs-option'>
|
23 |
|
24 |
<label for='shipping_title'><?php _e( 'Shipping title', 'woocommerce-advanced-free-shipping' ); ?></label>
|
25 |
+
<input
|
26 |
+
type='text'
|
27 |
+
id='shipping_title'
|
28 |
+
name='_wafs_shipping_method[shipping_title]'
|
29 |
+
value='<?php echo esc_attr( $settings['shipping_title'] ); ?>'
|
30 |
+
placeholder='<?php _e( 'e.g. Free Shipping', 'woocommerce-advanced-free-shipping' ); ?>'
|
31 |
+
>
|
32 |
|
33 |
</p>
|
34 |
|
includes/class-wafs-ajax.php
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
<?php
|
2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
-
*
|
7 |
*
|
8 |
-
* @
|
9 |
-
* @author Jeroen Sormani
|
10 |
-
* @package WooCommerce Advanced Free Shipping
|
11 |
* @version 1.0.0
|
12 |
*/
|
13 |
class WAFS_Ajax {
|
@@ -16,8 +15,6 @@ class WAFS_Ajax {
|
|
16 |
/**
|
17 |
* Constructor.
|
18 |
*
|
19 |
-
* Add ajax actions in order to work.
|
20 |
-
*
|
21 |
* @since 1.0.0
|
22 |
*/
|
23 |
public function __construct() {
|
@@ -36,15 +33,17 @@ class WAFS_Ajax {
|
|
36 |
/**
|
37 |
* Add condition.
|
38 |
*
|
39 |
-
*
|
40 |
*
|
41 |
* @since 1.0.0
|
42 |
*/
|
43 |
public function add_condition() {
|
44 |
|
45 |
-
check_ajax_referer( '
|
|
|
|
|
|
|
46 |
|
47 |
-
new WAFS_Condition( null, $_POST['group'] );
|
48 |
die();
|
49 |
|
50 |
}
|
@@ -53,23 +52,25 @@ class WAFS_Ajax {
|
|
53 |
/**
|
54 |
* Condition group.
|
55 |
*
|
56 |
-
*
|
57 |
*
|
58 |
* @since 1.0.0
|
59 |
*/
|
60 |
public function add_condition_group() {
|
61 |
|
62 |
-
check_ajax_referer( '
|
|
|
63 |
|
64 |
-
?><div class='condition-group condition-group-<?php echo
|
65 |
|
66 |
-
<p class='
|
67 |
|
68 |
-
new WAFS_Condition( null, $
|
|
|
69 |
|
70 |
?></div>
|
71 |
|
72 |
-
<p><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
|
73 |
|
74 |
die();
|
75 |
|
@@ -77,17 +78,23 @@ class WAFS_Ajax {
|
|
77 |
|
78 |
|
79 |
/**
|
80 |
-
* Update
|
81 |
*
|
82 |
-
*
|
83 |
*
|
84 |
* @since 1.0.0
|
85 |
*/
|
86 |
public function update_condition_value() {
|
87 |
|
88 |
-
check_ajax_referer( '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
wafs_condition_values( $_POST['id'], $_POST['group'], $_POST['condition'] );
|
91 |
die();
|
92 |
|
93 |
}
|
@@ -102,9 +109,20 @@ class WAFS_Ajax {
|
|
102 |
*/
|
103 |
public function update_condition_description() {
|
104 |
|
105 |
-
check_ajax_referer( '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
-
wafs_condition_description( $_POST['condition'] );
|
108 |
die();
|
109 |
|
110 |
}
|
1 |
<?php
|
2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
/**
|
5 |
+
* AJAX class.
|
6 |
*
|
7 |
+
* Handles all AJAX related calls.
|
8 |
*
|
9 |
+
* @author Jeroen Sormani
|
|
|
|
|
10 |
* @version 1.0.0
|
11 |
*/
|
12 |
class WAFS_Ajax {
|
15 |
/**
|
16 |
* Constructor.
|
17 |
*
|
|
|
|
|
18 |
* @since 1.0.0
|
19 |
*/
|
20 |
public function __construct() {
|
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 |
}
|
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 |
|
78 |
|
79 |
|
80 |
/**
|
81 |
+
* Update condition value field.
|
82 |
*
|
83 |
+
* Output the HTML of the value field according to the condition key..
|
84 |
*
|
85 |
* @since 1.0.0
|
86 |
*/
|
87 |
public function update_condition_value() {
|
88 |
|
89 |
+
check_ajax_referer( 'wpc-ajax-nonce', 'nonce' );
|
90 |
+
|
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 |
|
|
|
98 |
die();
|
99 |
|
100 |
}
|
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 |
}
|
includes/class-wafs-match-conditions.php
CHANGED
@@ -55,7 +55,7 @@ class WAFS_Match_Conditions {
|
|
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
|
59 |
*/
|
60 |
public function wafs_match_condition_subtotal( $match, $operator, $value ) {
|
61 |
|
@@ -86,7 +86,7 @@ class WAFS_Match_Conditions {
|
|
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
|
90 |
*/
|
91 |
public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
|
92 |
|
@@ -117,7 +117,7 @@ class WAFS_Match_Conditions {
|
|
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
|
121 |
*/
|
122 |
public function wafs_match_condition_tax( $match, $operator, $value ) {
|
123 |
|
@@ -151,7 +151,7 @@ class WAFS_Match_Conditions {
|
|
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
|
155 |
*/
|
156 |
public function wafs_match_condition_quantity( $match, $operator, $value ) {
|
157 |
|
@@ -182,12 +182,13 @@ class WAFS_Match_Conditions {
|
|
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
|
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 |
foreach ( WC()->cart->cart_contents as $product ) :
|
192 |
$product_ids[] = $product['product_id'];
|
193 |
endforeach;
|
@@ -213,18 +214,60 @@ class WAFS_Match_Conditions {
|
|
213 |
* @param bool $match Current match value.
|
214 |
* @param string $operator Operator selected by the user in the condition row.
|
215 |
* @param mixed $value Value given by the user in the condition row.
|
216 |
-
* @return
|
217 |
*/
|
218 |
public function wafs_match_condition_coupon( $match, $operator, $value ) {
|
219 |
|
220 |
-
if ( ! isset( WC()->cart ) )
|
221 |
-
|
222 |
-
if ( '==' == $operator ) :
|
223 |
-
$match = ( in_array( $value, WC()->cart->applied_coupons ) );
|
224 |
-
elseif ( '!=' == $operator ) :
|
225 |
-
$match = ( ! in_array( $value, WC()->cart->applied_coupons ) );
|
226 |
endif;
|
227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
return $match;
|
229 |
|
230 |
}
|
@@ -240,7 +283,7 @@ class WAFS_Match_Conditions {
|
|
240 |
* @param bool $match Current match value.
|
241 |
* @param string $operator Operator selected by the user in the condition row.
|
242 |
* @param mixed $value Value given by the user in the condition row.
|
243 |
-
* @return
|
244 |
*/
|
245 |
public function wafs_match_condition_weight( $match, $operator, $value ) {
|
246 |
|
@@ -268,23 +311,24 @@ class WAFS_Match_Conditions {
|
|
268 |
*
|
269 |
* @since 1.1.0
|
270 |
*
|
271 |
-
* @param
|
272 |
-
* @param
|
273 |
-
* @param
|
274 |
-
* @return
|
|
|
275 |
public function wafs_match_condition_contains_shipping_class( $match, $operator, $value ) {
|
276 |
|
277 |
if ( ! isset( WC()->cart ) ) return $match;
|
278 |
|
|
|
279 |
if ( $operator == '!=' ) :
|
280 |
-
// True until proven false
|
281 |
$match = true;
|
282 |
endif;
|
283 |
|
284 |
foreach ( WC()->cart->cart_contents as $product ) :
|
285 |
|
286 |
$id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
|
287 |
-
$product =
|
288 |
|
289 |
if ( $operator == '==' ) :
|
290 |
if ( $product->get_shipping_class() == $value ) :
|
@@ -318,32 +362,97 @@ class WAFS_Match_Conditions {
|
|
318 |
* @param bool $match Current match value.
|
319 |
* @param string $operator Operator selected by the user in the condition row.
|
320 |
* @param mixed $value Value given by the user in the condition row.
|
321 |
-
* @return
|
322 |
*/
|
323 |
public function wafs_match_condition_zipcode( $match, $operator, $value ) {
|
324 |
|
325 |
if ( ! isset( WC()->customer ) ) return $match;
|
326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
if ( '==' == $operator ) :
|
328 |
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
|
335 |
elseif ( '!=' == $operator ) :
|
336 |
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
|
343 |
elseif ( '>=' == $operator ) :
|
344 |
-
$match = ( (
|
345 |
elseif ( '<=' == $operator ) :
|
346 |
-
$match = ( (
|
347 |
endif;
|
348 |
|
349 |
return $match;
|
@@ -361,16 +470,31 @@ class WAFS_Match_Conditions {
|
|
361 |
* @param bool $match Current match value.
|
362 |
* @param string $operator Operator selected by the user in the condition row.
|
363 |
* @param mixed $value Value given by the user in the condition row.
|
364 |
-
* @return
|
365 |
*/
|
366 |
public function wafs_match_condition_city( $match, $operator, $value ) {
|
367 |
|
368 |
if ( ! isset( WC()->customer ) ) return $match;
|
369 |
|
|
|
|
|
|
|
370 |
if ( '==' == $operator ) :
|
371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
elseif ( '!=' == $operator ) :
|
373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
374 |
endif;
|
375 |
|
376 |
return $match;
|
@@ -388,7 +512,7 @@ class WAFS_Match_Conditions {
|
|
388 |
* @param bool $match Current match value.
|
389 |
* @param string $operator Operator selected by the user in the condition row.
|
390 |
* @param mixed $value Value given by the user in the condition row.
|
391 |
-
* @return
|
392 |
*/
|
393 |
public function wafs_match_condition_state( $match, $operator, $value ) {
|
394 |
|
@@ -417,7 +541,7 @@ class WAFS_Match_Conditions {
|
|
417 |
* @param bool $match Current match value.
|
418 |
* @param string $operator Operator selected by the user in the condition row.
|
419 |
* @param mixed $value Value given by the user in the condition row.
|
420 |
-
* @return
|
421 |
*/
|
422 |
public function wafs_match_condition_country( $match, $operator, $value ) {
|
423 |
|
@@ -445,7 +569,7 @@ class WAFS_Match_Conditions {
|
|
445 |
* @param bool $match Current match value.
|
446 |
* @param string $operator Operator selected by the user in the condition row.
|
447 |
* @param mixed $value Value given by the user in the condition row.
|
448 |
-
* @return
|
449 |
*/
|
450 |
public function wafs_match_condition_role( $match, $operator, $value ) {
|
451 |
|
@@ -477,7 +601,7 @@ class WAFS_Match_Conditions {
|
|
477 |
* @param bool $match Current match value.
|
478 |
* @param string $operator Operator selected by the user in the condition row.
|
479 |
* @param mixed $value Value given by the user in the condition row.
|
480 |
-
* @return
|
481 |
*/
|
482 |
public function wafs_match_condition_width( $match, $operator, $value ) {
|
483 |
|
@@ -520,7 +644,7 @@ class WAFS_Match_Conditions {
|
|
520 |
* @param bool $match Current match value.
|
521 |
* @param string $operator Operator selected by the user in the condition row.
|
522 |
* @param mixed $value Value given by the user in the condition row.
|
523 |
-
* @return
|
524 |
*/
|
525 |
public function wafs_match_condition_height( $match, $operator, $value ) {
|
526 |
|
@@ -563,7 +687,7 @@ class WAFS_Match_Conditions {
|
|
563 |
* @param bool $match Current match value.
|
564 |
* @param string $operator Operator selected by the user in the condition row.
|
565 |
* @param mixed $value Value given by the user in the condition row.
|
566 |
-
* @return
|
567 |
*/
|
568 |
public function wafs_match_condition_length( $match, $operator, $value ) {
|
569 |
|
@@ -606,7 +730,7 @@ class WAFS_Match_Conditions {
|
|
606 |
* @param bool $match Current match value.
|
607 |
* @param string $operator Operator selected by the user in the condition row.
|
608 |
* @param mixed $value Value given by the user in the condition row.
|
609 |
-
* @return
|
610 |
*/
|
611 |
public function wafs_match_condition_stock( $match, $operator, $value ) {
|
612 |
|
@@ -639,14 +763,14 @@ class WAFS_Match_Conditions {
|
|
639 |
/**
|
640 |
* Stock status.
|
641 |
*
|
642 |
-
* Match the condition value against all cart products stock
|
643 |
*
|
644 |
* @since 1.0.0
|
645 |
*
|
646 |
* @param bool $match Current match value.
|
647 |
* @param string $operator Operator selected by the user in the condition row.
|
648 |
* @param mixed $value Value given by the user in the condition row.
|
649 |
-
* @return
|
650 |
*/
|
651 |
public function wafs_match_condition_stock_status( $match, $operator, $value ) {
|
652 |
|
@@ -688,7 +812,7 @@ class WAFS_Match_Conditions {
|
|
688 |
* @param bool $match Current match value.
|
689 |
* @param string $operator Operator selected by the user in the condition row.
|
690 |
* @param mixed $value Value given by the user in the condition row.
|
691 |
-
* @return
|
692 |
*/
|
693 |
public function wafs_match_condition_category( $match, $operator, $value ) {
|
694 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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;
|
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 |
}
|
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 |
|
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 ) :
|
362 |
* @param bool $match Current match value.
|
363 |
* @param string $operator Operator selected by the user in the condition row.
|
364 |
* @param mixed $value Value given by the user in the condition row.
|
365 |
+
* @return bool Matching result, true if results match, otherwise false.
|
366 |
*/
|
367 |
public function wafs_match_condition_zipcode( $match, $operator, $value ) {
|
368 |
|
369 |
if ( ! isset( WC()->customer ) ) return $match;
|
370 |
|
371 |
+
$user_zipcode = WC()->customer->get_shipping_postcode();
|
372 |
+
|
373 |
+
// Prepare allowed values.
|
374 |
+
$zipcodes = (array) preg_split( '/,+ */', $value );
|
375 |
+
|
376 |
+
// Remove all non- letters and numbers
|
377 |
+
foreach ( $zipcodes as $key => $zipcode ) :
|
378 |
+
$zipcodes[ $key ] = preg_replace( '/[^0-9a-zA-Z-\*]/', '', $zipcode );
|
379 |
+
endforeach;
|
380 |
+
|
381 |
if ( '==' == $operator ) :
|
382 |
|
383 |
+
foreach ( $zipcodes as $zipcode ) :
|
384 |
+
|
385 |
+
// @since 1.0.9 - Wildcard support (*)
|
386 |
+
if ( strpos( $zipcode, '*' ) !== false ) :
|
387 |
+
|
388 |
+
$user_zipcode = preg_replace( '/[^0-9a-zA-Z]/', '', $user_zipcode );
|
389 |
+
$zipcode = str_replace( '*', '', $zipcode );
|
390 |
+
|
391 |
+
if ( empty( $zipcode ) ) continue;
|
392 |
+
|
393 |
+
$parts = explode( '-', $zipcode );
|
394 |
+
if ( count( $parts ) > 1 ) :
|
395 |
+
$match = ( $user_zipcode >= min( $parts ) && $user_zipcode <= max( $parts ) );
|
396 |
+
else :
|
397 |
+
$match = preg_match( '/^' . preg_quote( $zipcode, '/' ) . '/i', $user_zipcode );
|
398 |
+
endif;
|
399 |
+
|
400 |
+
else :
|
401 |
+
|
402 |
+
// BC when not using asterisk (wildcard)
|
403 |
+
$match = ( (double) $user_zipcode == (double) $zipcode );
|
404 |
+
|
405 |
+
endif;
|
406 |
+
|
407 |
+
if ( $match == true ) {
|
408 |
+
return true;
|
409 |
+
}
|
410 |
+
|
411 |
+
endforeach;
|
412 |
|
413 |
elseif ( '!=' == $operator ) :
|
414 |
|
415 |
+
// True until proven false
|
416 |
+
$match = true;
|
417 |
+
|
418 |
+
foreach ( $zipcodes as $zipcode ) :
|
419 |
+
|
420 |
+
// @since 1.0.9 - Wildcard support (*)
|
421 |
+
if ( strpos( $zipcode, '*' ) !== false ) :
|
422 |
+
|
423 |
+
$user_zipcode = preg_replace( '/[^0-9a-zA-Z]/', '', $user_zipcode );
|
424 |
+
$zipcode = str_replace( '*', '', $zipcode );
|
425 |
+
|
426 |
+
if ( empty( $zipcode ) ) continue;
|
427 |
+
|
428 |
+
$parts = explode( '-', $zipcode );
|
429 |
+
if ( count( $parts ) > 1 ) :
|
430 |
+
$zipcode_match = ( $user_zipcode >= min( $parts ) && $user_zipcode <= max( $parts ) );
|
431 |
+
else :
|
432 |
+
$zipcode_match = preg_match( '/^' . preg_quote( $zipcode, '/' ) . '/i', $user_zipcode );
|
433 |
+
endif;
|
434 |
+
|
435 |
+
if ( $zipcode_match == true ) :
|
436 |
+
return $match = false;
|
437 |
+
endif;
|
438 |
+
|
439 |
+
else :
|
440 |
+
|
441 |
+
// BC when not using asterisk (wildcard)
|
442 |
+
$zipcode_match = ( (double) $user_zipcode == (double) $zipcode );
|
443 |
+
|
444 |
+
if ( $zipcode_match == true ) :
|
445 |
+
return $match = false;
|
446 |
+
endif;
|
447 |
+
|
448 |
+
endif;
|
449 |
+
|
450 |
+
endforeach;
|
451 |
|
452 |
elseif ( '>=' == $operator ) :
|
453 |
+
$match = ( (double) $user_zipcode >= (double) $value );
|
454 |
elseif ( '<=' == $operator ) :
|
455 |
+
$match = ( (double) $user_zipcode <= (double) $value );
|
456 |
endif;
|
457 |
|
458 |
return $match;
|
470 |
* @param bool $match Current match value.
|
471 |
* @param string $operator Operator selected by the user in the condition row.
|
472 |
* @param mixed $value Value given by the user in the condition row.
|
473 |
+
* @return bool Matching result, true if results match, otherwise false.
|
474 |
*/
|
475 |
public function wafs_match_condition_city( $match, $operator, $value ) {
|
476 |
|
477 |
if ( ! isset( WC()->customer ) ) return $match;
|
478 |
|
479 |
+
$customer_city = strtolower( WC()->customer->get_shipping_city() );
|
480 |
+
$value = strtolower( $value );
|
481 |
+
|
482 |
if ( '==' == $operator ) :
|
483 |
+
|
484 |
+
if ( preg_match( '/\, ?/', $value ) ) :
|
485 |
+
$match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
|
486 |
+
else :
|
487 |
+
$match = ( $value == $customer_city );
|
488 |
+
endif;
|
489 |
+
|
490 |
elseif ( '!=' == $operator ) :
|
491 |
+
|
492 |
+
if ( preg_match( '/\, ?/', $value ) ) :
|
493 |
+
$match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
|
494 |
+
else :
|
495 |
+
$match = ( $value == $customer_city );
|
496 |
+
endif;
|
497 |
+
|
498 |
endif;
|
499 |
|
500 |
return $match;
|
512 |
* @param bool $match Current match value.
|
513 |
* @param string $operator Operator selected by the user in the condition row.
|
514 |
* @param mixed $value Value given by the user in the condition row.
|
515 |
+
* @return bool Matching result, true if results match, otherwise false.
|
516 |
*/
|
517 |
public function wafs_match_condition_state( $match, $operator, $value ) {
|
518 |
|
541 |
* @param bool $match Current match value.
|
542 |
* @param string $operator Operator selected by the user in the condition row.
|
543 |
* @param mixed $value Value given by the user in the condition row.
|
544 |
+
* @return bool Matching result, true if results match, otherwise false.
|
545 |
*/
|
546 |
public function wafs_match_condition_country( $match, $operator, $value ) {
|
547 |
|
569 |
* @param bool $match Current match value.
|
570 |
* @param string $operator Operator selected by the user in the condition row.
|
571 |
* @param mixed $value Value given by the user in the condition row.
|
572 |
+
* @return bool Matching result, true if results match, otherwise false.
|
573 |
*/
|
574 |
public function wafs_match_condition_role( $match, $operator, $value ) {
|
575 |
|
601 |
* @param bool $match Current match value.
|
602 |
* @param string $operator Operator selected by the user in the condition row.
|
603 |
* @param mixed $value Value given by the user in the condition row.
|
604 |
+
* @return bool Matching result, true if results match, otherwise false.
|
605 |
*/
|
606 |
public function wafs_match_condition_width( $match, $operator, $value ) {
|
607 |
|
644 |
* @param bool $match Current match value.
|
645 |
* @param string $operator Operator selected by the user in the condition row.
|
646 |
* @param mixed $value Value given by the user in the condition row.
|
647 |
+
* @return bool Matching result, true if results match, otherwise false.
|
648 |
*/
|
649 |
public function wafs_match_condition_height( $match, $operator, $value ) {
|
650 |
|
687 |
* @param bool $match Current match value.
|
688 |
* @param string $operator Operator selected by the user in the condition row.
|
689 |
* @param mixed $value Value given by the user in the condition row.
|
690 |
+
* @return bool Matching result, true if results match, otherwise false.
|
691 |
*/
|
692 |
public function wafs_match_condition_length( $match, $operator, $value ) {
|
693 |
|
730 |
* @param bool $match Current match value.
|
731 |
* @param string $operator Operator selected by the user in the condition row.
|
732 |
* @param mixed $value Value given by the user in the condition row.
|
733 |
+
* @return bool Matching result, true if results match, otherwise false.
|
734 |
*/
|
735 |
public function wafs_match_condition_stock( $match, $operator, $value ) {
|
736 |
|
763 |
/**
|
764 |
* Stock status.
|
765 |
*
|
766 |
+
* Match the condition value against all cart products stock statuses.
|
767 |
*
|
768 |
* @since 1.0.0
|
769 |
*
|
770 |
* @param bool $match Current match value.
|
771 |
* @param string $operator Operator selected by the user in the condition row.
|
772 |
* @param mixed $value Value given by the user in the condition row.
|
773 |
+
* @return bool Matching result, true if results match, otherwise false.
|
774 |
*/
|
775 |
public function wafs_match_condition_stock_status( $match, $operator, $value ) {
|
776 |
|
812 |
* @param bool $match Current match value.
|
813 |
* @param string $operator Operator selected by the user in the condition row.
|
814 |
* @param mixed $value Value given by the user in the condition row.
|
815 |
+
* @return bool Matching result, true if results match, otherwise false.
|
816 |
*/
|
817 |
public function wafs_match_condition_category( $match, $operator, $value ) {
|
818 |
|
includes/class-wafs-method.php
CHANGED
@@ -17,7 +17,7 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
17 |
$this->id = 'advanced_free_shipping';
|
18 |
$this->title = __( 'Free Shipping (configurable per rate)', 'woocommerce-advanced-free-shipping' );
|
19 |
$this->method_title = __( 'Advanced Free Shipping', 'woocommerce-advanced-free-shipping' );
|
20 |
-
$this->method_description = __( 'Configure
|
21 |
|
22 |
$this->matched_methods = $this->wafs_match_methods();
|
23 |
|
@@ -61,7 +61,7 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
61 |
*/
|
62 |
public function wafs_match_methods() {
|
63 |
|
64 |
-
$methods =
|
65 |
|
66 |
$matched_methods = '';
|
67 |
foreach ( $methods as $method ) :
|
@@ -91,7 +91,7 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
91 |
* @since 1.0.0
|
92 |
*
|
93 |
* @param array $condition_groups All condition groups set by the user.
|
94 |
-
* @return
|
95 |
*/
|
96 |
public function wafs_match_conditions( $condition_groups = array() ) {
|
97 |
|
@@ -133,10 +133,10 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
133 |
public function init_form_fields() {
|
134 |
|
135 |
$this->form_fields = array(
|
136 |
-
'enabled'
|
137 |
'title' => __( 'Enable/Disable', 'woocommerce' ),
|
138 |
'type' => 'checkbox',
|
139 |
-
'label' => __( 'Enable Advanced Free Shipping', 'woocommerce-advanced-free-shipping' ),
|
140 |
'default' => 'yes'
|
141 |
),
|
142 |
'hide_other_shipping' => array(
|
17 |
$this->id = 'advanced_free_shipping';
|
18 |
$this->title = __( 'Free Shipping (configurable per rate)', 'woocommerce-advanced-free-shipping' );
|
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 |
|
61 |
*/
|
62 |
public function wafs_match_methods() {
|
63 |
|
64 |
+
$methods = wafs_get_rates();
|
65 |
|
66 |
$matched_methods = '';
|
67 |
foreach ( $methods as $method ) :
|
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 |
|
133 |
public function init_form_fields() {
|
134 |
|
135 |
$this->form_fields = array(
|
136 |
+
'enabled' => array(
|
137 |
'title' => __( 'Enable/Disable', 'woocommerce' ),
|
138 |
'type' => 'checkbox',
|
139 |
+
'label' => __( 'Enable the Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ),
|
140 |
'default' => 'yes'
|
141 |
),
|
142 |
'hide_other_shipping' => array(
|
includes/class-wafs-post-type.php
CHANGED
@@ -111,10 +111,10 @@ class WAFS_post_type {
|
|
111 |
if ( 'wafs' == $post_type ) :
|
112 |
$overview_link = admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=wafs_free_shipping_method' );
|
113 |
|
114 |
-
$overview
|
115 |
-
$messages[ $post_type ][1]
|
116 |
-
$messages[ $post_type ][6]
|
117 |
-
$messages[ $post_type ][9]
|
118 |
$messages[ $post_type ][8] .= $overview;
|
119 |
$messages[ $post_type ][10] .= $overview;
|
120 |
|
@@ -152,7 +152,7 @@ class WAFS_post_type {
|
|
152 |
/**
|
153 |
* Load meta box conditions view.
|
154 |
*/
|
155 |
-
require_once plugin_dir_path( __FILE__ ) . 'admin/
|
156 |
|
157 |
}
|
158 |
|
@@ -169,7 +169,7 @@ class WAFS_post_type {
|
|
169 |
/**
|
170 |
* Load meta box settings view
|
171 |
*/
|
172 |
-
require_once plugin_dir_path( __FILE__ ) . 'admin/
|
173 |
|
174 |
}
|
175 |
|
@@ -183,7 +183,7 @@ class WAFS_post_type {
|
|
183 |
*/
|
184 |
public function save_condition_meta( $post_id ) {
|
185 |
|
186 |
-
if ( ! isset( $_POST['
|
187 |
return $post_id;
|
188 |
endif;
|
189 |
|
@@ -195,7 +195,7 @@ class WAFS_post_type {
|
|
195 |
return $post_id;
|
196 |
endif;
|
197 |
|
198 |
-
$shipping_method_conditions = $_POST['
|
199 |
|
200 |
update_post_meta( $post_id, '_wafs_shipping_method_conditions', $shipping_method_conditions );
|
201 |
|
@@ -260,4 +260,4 @@ class WAFS_post_type {
|
|
260 |
/**
|
261 |
* Load condition object
|
262 |
*/
|
263 |
-
require_once plugin_dir_path( __FILE__ ) . 'admin/
|
111 |
if ( 'wafs' == $post_type ) :
|
112 |
$overview_link = admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=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;
|
116 |
+
$messages[ $post_type ][6] .= $overview;
|
117 |
+
$messages[ $post_type ][9] .= $overview;
|
118 |
$messages[ $post_type ][8] .= $overview;
|
119 |
$messages[ $post_type ][10] .= $overview;
|
120 |
|
152 |
/**
|
153 |
* Load meta box conditions view.
|
154 |
*/
|
155 |
+
require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-conditions.php';
|
156 |
|
157 |
}
|
158 |
|
169 |
/**
|
170 |
* Load meta box settings view
|
171 |
*/
|
172 |
+
require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-settings.php';
|
173 |
|
174 |
}
|
175 |
|
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 |
|
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 |
|
260 |
/**
|
261 |
* Load condition object
|
262 |
*/
|
263 |
+
require_once plugin_dir_path( __FILE__ ) . 'admin/class-wafs-condition.php';
|
includes/core-functions.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Get Advanced Free Shipping rates.
|
6 |
+
*
|
7 |
+
* Get a list of all the Advanced Free shipping rates.
|
8 |
+
*
|
9 |
+
* @since 1.0.10
|
10 |
+
*
|
11 |
+
* @param array $args List of arguments to merge with the default args.
|
12 |
+
* @return array List of 'wafs' posts.
|
13 |
+
*/
|
14 |
+
function wafs_get_rates( $args = array() ) {
|
15 |
+
|
16 |
+
$query_args = wp_parse_args( $args, array(
|
17 |
+
'post_type' => 'wafs',
|
18 |
+
'post_status' => 'publish',
|
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 |
+
}
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
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 |
-
Stable tag: 1.0.
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
@@ -65,6 +65,17 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
|
|
65 |
|
66 |
== Changelog ==
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
= 1.0.9 - 16-06-2016 =
|
69 |
|
70 |
* [Fix] - Fix a notice that was introduced with a change in WooCommerce 2.6
|
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.10
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
65 |
|
66 |
== Changelog ==
|
67 |
|
68 |
+
= 1.0.10 - 25-08-2016 =
|
69 |
+
|
70 |
+
* [Improvement] - Optimized asset scripts
|
71 |
+
* [Improvement] - Refactored condition code (backend)
|
72 |
+
* [Improvement] - Allow asterisk (*) in zipcode to allow 'begins with' type of matching functionality
|
73 |
+
* [Improvement] - Allow dollar and percentage signs in the 'coupon' condition to setup the condition based on the amounts instead of solely coupon codes
|
74 |
+
* [Improvement] - Add a link to the shipping rates overview page on the plugins page
|
75 |
+
* [Improvement] - Add support for continents in the 'country' condition (requires WC 2.6+)
|
76 |
+
* [Improvement] - Improved 'product' condition value fields (allow searching) and supports huge amounts of product
|
77 |
+
* [Improvement] - Allow comma separated cities
|
78 |
+
|
79 |
= 1.0.9 - 16-06-2016 =
|
80 |
|
81 |
* [Fix] - Fix a notice that was introduced with a change in WooCommerce 2.6
|
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.
|
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.
|
52 |
|
53 |
|
54 |
/**
|
@@ -132,10 +132,13 @@ class WooCommerce_Advanced_Free_Shipping {
|
|
132 |
// Updater
|
133 |
$this->update();
|
134 |
|
|
|
|
|
|
|
135 |
/**
|
136 |
* Require matching conditions hooks.
|
137 |
*/
|
138 |
-
require_once plugin_dir_path( __FILE__ ) . '
|
139 |
$this->matcher = new Wafs_Match_Conditions();
|
140 |
|
141 |
/**
|
@@ -147,14 +150,16 @@ class WooCommerce_Advanced_Free_Shipping {
|
|
147 |
/**
|
148 |
* Load ajax methods
|
149 |
*/
|
150 |
-
require_once plugin_dir_path( __FILE__ ) . '
|
151 |
$this->ajax = new WAFS_Ajax();
|
152 |
|
153 |
/**
|
154 |
* Admin class
|
155 |
*/
|
156 |
if ( is_admin() ) :
|
157 |
-
require_once plugin_dir_path( __FILE__ ) . '
|
|
|
|
|
158 |
$this->admin = new WAFS_Admin();
|
159 |
endif;
|
160 |
|
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.10
|
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.0.10';
|
52 |
|
53 |
|
54 |
/**
|
132 |
// Updater
|
133 |
$this->update();
|
134 |
|
135 |
+
// Functions
|
136 |
+
require_once plugin_dir_path( __FILE__ ) . 'includes/core-functions.php';
|
137 |
+
|
138 |
/**
|
139 |
* Require matching conditions hooks.
|
140 |
*/
|
141 |
+
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wafs-match-conditions.php';
|
142 |
$this->matcher = new Wafs_Match_Conditions();
|
143 |
|
144 |
/**
|
150 |
/**
|
151 |
* Load ajax methods
|
152 |
*/
|
153 |
+
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wafs-ajax.php';
|
154 |
$this->ajax = new WAFS_Ajax();
|
155 |
|
156 |
/**
|
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 |
|