Version Description
- 06-03-2017
Download this release
Release Info
Developer | sormano |
Plugin | WooCommerce Advanced Free Shipping |
Version | 1.1.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.11 to 1.1.0
- assets/css/woocommerce-advanced-free-shipping.min.css +1 -1
- assets/css/woocommerce-advanced-free-shipping.scss +1 -61
- assets/js/woocommerce-advanced-free-shipping.js +0 -104
- assets/js/woocommerce-advanced-free-shipping.min.js +0 -1
- codeoversight.yml +6 -2
- includes/admin/admin-functions.php +0 -100
- includes/admin/class-wafs-admin.php +9 -11
- includes/admin/class-wafs-condition.php +17 -164
- includes/admin/views/conditions-table.php +1 -1
- includes/admin/views/html-condition-group.php +39 -0
- includes/admin/views/html-condition-row.php +11 -11
- includes/admin/views/meta-box-conditions.php +10 -20
- includes/admin/views/meta-box-settings.php +0 -1
- includes/class-wafs-ajax.php +1 -81
- includes/class-wafs-match-conditions.php +0 -734
- includes/class-wafs-method.php +11 -72
- includes/class-wafs-post-type.php +19 -56
- includes/core-functions.php +53 -2
- libraries/wp-conditions/admin-functions.php +181 -0
- libraries/wp-conditions/assets/css/wp-conditions.min.css +1 -0
- {assets/css/parts → libraries/wp-conditions/assets/css}/wp-conditions.scss +116 -14
- libraries/wp-conditions/assets/js/repeater/jquery.repeater.js +57 -0
- libraries/wp-conditions/assets/js/repeater/jquery.repeater.min.js +1 -0
- libraries/wp-conditions/assets/js/wp-conditions.js +175 -0
- libraries/wp-conditions/assets/js/wp-conditions.min.js +1 -0
- libraries/wp-conditions/conditions/wpc-category-condition.php +74 -0
- libraries/wp-conditions/conditions/wpc-city-condition.php +66 -0
- libraries/wp-conditions/conditions/wpc-condition.php +123 -0
- libraries/wp-conditions/conditions/wpc-contains-category-condition.php +74 -0
- libraries/wp-conditions/conditions/wpc-contains-product-condition.php +78 -0
- libraries/wp-conditions/conditions/wpc-contains-shipping-class-condition.php +72 -0
- libraries/wp-conditions/conditions/wpc-country-condition.php +87 -0
- libraries/wp-conditions/conditions/wpc-coupon-condition.php +76 -0
- libraries/wp-conditions/conditions/wpc-date-condition.php +39 -0
- libraries/wp-conditions/conditions/wpc-day-condition.php +43 -0
- libraries/wp-conditions/conditions/wpc-fallback-condition.php +28 -0
- libraries/wp-conditions/conditions/wpc-height-condition.php +36 -0
- libraries/wp-conditions/conditions/wpc-length-condition.php +36 -0
- libraries/wp-conditions/conditions/wpc-page-condition.php +100 -0
- libraries/wp-conditions/conditions/wpc-payment-gateway-condition.php +48 -0
- libraries/wp-conditions/conditions/wpc-quantity-condition.php +33 -0
- libraries/wp-conditions/conditions/wpc-role-condition.php +64 -0
- libraries/wp-conditions/conditions/wpc-shipping-method-condition.php +134 -0
- libraries/wp-conditions/conditions/wpc-state-condition.php +59 -0
- libraries/wp-conditions/conditions/wpc-stock-condition.php +39 -0
- libraries/wp-conditions/conditions/wpc-stock-status-condition.php +74 -0
- libraries/wp-conditions/conditions/wpc-subtotal-condition.php +28 -0
- libraries/wp-conditions/conditions/wpc-subtotal-ex-tax-condition.php +27 -0
- libraries/wp-conditions/conditions/wpc-tax-condition.php +27 -0
- libraries/wp-conditions/conditions/wpc-time-condition.php +39 -0
- libraries/wp-conditions/conditions/wpc-weight-condition.php +28 -0
- libraries/wp-conditions/conditions/wpc-width-condition.php +36 -0
- libraries/wp-conditions/conditions/wpc-zipcode-condition.php +81 -0
- libraries/wp-conditions/functions.php +297 -0
- readme.txt +89 -42
- woocommerce-advanced-free-shipping.php +18 -14
assets/css/woocommerce-advanced-free-shipping.min.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
.wpc-conditions .wpc-condition-group{
|
1 |
+
.wpc-conditions .wpc-condition-group{background-color:#f5f5f5;padding:15px;border:1px solid #e5e5e5;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04);min-height:30px;margin:0 -13px 1.5em}.wpc-conditions .wpc-condition-group:hover .wpc-condition-group-actions{opacity:1}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions{opacity:0;margin:-10px -10px 0 0;font-size:80%}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a{text-decoration:none}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete{color:#a00}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete:hover{color:#f00}.wpc-conditions .wpc-condition-group .wpc-condition-wrap{margin:10px 0 5px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-condition{width:35%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-operator{width:22.5%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-value{width:calc( 42.5% - 75px );height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description{float:right}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip{height:28px;line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip:after{line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap input{vertical-align:top}.wpc-conditions .clearfix:after{content:" ";display:block;height:0;clear:both}.wpc-conditions .wpc-add.button:before{font-family:'dashicons';content:"\f502";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;margin-right:5px;color:#667}.wpc-conditions .wpc-condition-delete.button{font-weight:600;width:30px;text-align:center;padding:0}.wpc-conditions .wpc-condition-delete.button:before{font-family:'dashicons';content:"\f460";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;color:#667}.wpc-conditions>p+.wpc-condition-group-wrap p.or-text{display:none}.wpc-conditions .or-text{margin:1.5em 0}.wpc-conditions .match-text{margin:0 0 1em}.wpc-conditions .wpc-condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wpc-conditions .wpc-condition-wrap:hover .wpc-condition-delete{display:inline-block;opacity:1}.wpc-conditions .wpc-condition-wrap.loading{height:30px}.wpc-conditions .wpc-condition-wrap.loading .loading-icon{width:100%;clear:both;display:block;text-align:center;line-height:110%;margin:0 1px}.wpc-condition-wrap .wpc-value.select2-container{display:inline-block !important;margin:1px}.wpc-condition-wrap .wpc-value.select2-container.select2-container-active .select2-choice{border:1px solid #666}.wpc-condition-wrap .wpc-value.select2-container.select2-drop-above .select2-choice{border-radius:0 0 4px 4px;border:1px solid #666;border-top-color:transparent}.wpc-condition-wrap .wpc-value.select2-container .select2-choice{border-color:#ddd;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;height:26px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07)}.wpc-condition-wrap .wpc-value.select2-dropdown-open .select2-choice{border-bottom-color:transparent;-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset;border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid #666;outline:0}.wpc-condition-wrap .select2-container .select2-selection--single{height:28px !important}.wpc-condition-wrap .select2-container .select2-selection--single #select2--container,.wpc-condition-wrap .select2-container .select2-selection--single .select2-selection__arrow{line-height:26px}.wpc-condition-wrap .select2-container .select2-selection--single .select2-selection__arrow{height:28px}.wpc-conditions-post-table .sort{padding:0 4px;cursor:move;text-align:center;vertical-align:middle}.wpc-conditions-post-table .sort:before{content:"\e032";font-family:WooCommerce;text-align:center;line-height:1;color:#999;display:block;width:100%;float:left;height:100%}.wpc-conditions-post-table .sort:before,.wpc-conditions-post-table .row-actions{visibility:hidden !important}.wpc-conditions-post-table tr:hover .sort:before,.wpc-conditions-post-table tr:hover>td>.row-actions{visibility:visible !important}.wpc-conditions-post-table .add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}@media screen and (max-width: 782px){.wpc-conditions-post-table th{padding:8px}.wpc-conditions-post-table td{padding:8px 10px}.wpc-conditions-post-table tfoot .button{margin-bottom:0}}.wpc-currency{padding:3px 10px;font-size:14px;font-weight:400;line-height:19px;height:27px;box-sizing:border-box;color:#555;text-align:center;background-color:#EEE;border:1px solid #DDD;border-right:none;border-radius:4px 0px 0px 4px;margin:1px 0px 1px 1px;display:inline-block}.wpc-currency+input{margin-left:-4px;line-height:19px;width:161px !important}@media screen and (max-width: 782px){.wpc-currency{font-size:16px;padding:6px 10px;height:33px}}.post-type-wafs .misc-pub-visibility#visibility{display:none}.wafs-option label{display:inline-block;width:150px}.wafs_conditions_meta_box>p:first-child+div>.or_match{display:none}.wafs_desc{display:none;position:absolute;background:rgba(0,0,0,0.8);min-width:25px;max-width:200px;border-radius:6px;padding:5px 10px;color:white;margin-top:10px;right:40px;text-align:center}.wafs_desc:after{border-top:0px solid transparent;border-right:10px solid transparent;border-left:10px solid transparent;border-bottom:10px solid rgba(0,0,0,0.8);content:' ';position:absolute;top:-10px;right:10px;z-index:999}.wafs_tip:hover ~ .wafs_desc{display:block !important}.wafs-description{width:40px;float:right;line-height:20px}.condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wafs-condition-wrap:hover .condition-delete{display:inline-block;opacity:1}#advanced_free_shipping_shipping_methods tr .row-actions{visibility:hidden}#advanced_free_shipping_shipping_methods tr:hover>td>.row-actions{visibility:visible !important}
|
assets/css/woocommerce-advanced-free-shipping.scss
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
@import '
|
2 |
|
3 |
/* Hide visibility from admin */
|
4 |
.post-type-wafs .misc-pub-visibility#visibility {
|
@@ -13,37 +13,7 @@
|
|
13 |
.wafs_conditions_meta_box > p:first-child + div > .or_match {
|
14 |
display: none;
|
15 |
}
|
16 |
-
/*
|
17 |
-
* Condition group
|
18 |
-
*/
|
19 |
-
.condition-group {
|
20 |
-
margin-bottom: 30px;
|
21 |
-
background-color: #f5f5f5;
|
22 |
-
padding: 15px 20px 20px;
|
23 |
-
border: 1px solid #ddd;
|
24 |
-
-webkit-box-shadow: 0 1px 1px rgba( 0, 0, 0, .04);
|
25 |
-
box-shadow: 0 1px 1px rgba( 0, 0, 0, .04);
|
26 |
-
}
|
27 |
-
.wafs-condition-wrap {
|
28 |
-
margin: 10px 0px 5px;
|
29 |
-
}
|
30 |
-
.wafs-condition-wrap .wafs-condition {
|
31 |
-
width: 30%;
|
32 |
-
}
|
33 |
-
.wafs-condition-wrap .wafs-operator {
|
34 |
-
width: 12%;
|
35 |
-
min-width: 140px;
|
36 |
-
}
|
37 |
-
.wafs-condition-wrap .wafs-value {
|
38 |
-
width: 30%;
|
39 |
-
}
|
40 |
-
.wafs-condition-wrap input {
|
41 |
-
vertical-align: top;
|
42 |
-
}
|
43 |
|
44 |
-
#wafs_conditions p + p {
|
45 |
-
display: none;
|
46 |
-
}
|
47 |
/* Description */
|
48 |
.wafs_desc {
|
49 |
display: none;
|
@@ -78,23 +48,6 @@
|
|
78 |
line-height: 20px;
|
79 |
}
|
80 |
|
81 |
-
/*
|
82 |
-
* Loading icon
|
83 |
-
*/
|
84 |
-
|
85 |
-
/* Load icon condition row */
|
86 |
-
.wafs-condition-wrap ~ .loading-icon {
|
87 |
-
display: block;
|
88 |
-
}
|
89 |
-
.loading-icon {
|
90 |
-
width: 30%;
|
91 |
-
clear: both;
|
92 |
-
display: inline-block;
|
93 |
-
text-align: center;
|
94 |
-
line-height: 110%;
|
95 |
-
margin: 0 1px;
|
96 |
-
}
|
97 |
-
|
98 |
.condition-delete {
|
99 |
display: none;
|
100 |
opacity: 0;
|
@@ -105,19 +58,6 @@
|
|
105 |
opacity: 1;
|
106 |
}
|
107 |
|
108 |
-
|
109 |
-
/* WooCommerce Add icon */
|
110 |
-
.add.button:before {
|
111 |
-
font-family: WooCommerce;
|
112 |
-
speak: none;
|
113 |
-
font-weight: 400;
|
114 |
-
font-variant: normal;
|
115 |
-
text-transform: none;
|
116 |
-
line-height: 1;
|
117 |
-
-webkit-font-smoothing: antialiased;
|
118 |
-
margin-right: 7px;
|
119 |
-
content: "\e007";
|
120 |
-
}
|
121 |
/* Overview row actions */
|
122 |
#advanced_free_shipping_shipping_methods tr .row-actions {
|
123 |
visibility: hidden;
|
1 |
+
@import '../../libraries/wp-conditions/assets/css/wp-conditions';
|
2 |
|
3 |
/* Hide visibility from admin */
|
4 |
.post-type-wafs .misc-pub-visibility#visibility {
|
13 |
.wafs_conditions_meta_box > p:first-child + div > .or_match {
|
14 |
display: none;
|
15 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
|
|
|
|
|
|
17 |
/* Description */
|
18 |
.wafs_desc {
|
19 |
display: none;
|
48 |
line-height: 20px;
|
49 |
}
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
.condition-delete {
|
52 |
display: none;
|
53 |
opacity: 0;
|
58 |
opacity: 1;
|
59 |
}
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
/* Overview row actions */
|
62 |
#advanced_free_shipping_shipping_methods tr .row-actions {
|
63 |
visibility: hidden;
|
assets/js/woocommerce-advanced-free-shipping.js
DELETED
@@ -1,104 +0,0 @@
|
|
1 |
-
jQuery( function( $ ) {
|
2 |
-
|
3 |
-
/**************************************************************
|
4 |
-
* WPC - 1.0.1
|
5 |
-
*************************************************************/
|
6 |
-
|
7 |
-
// Add condition
|
8 |
-
$( document.body ).on( 'click', '.wpc-condition-add', function() {
|
9 |
-
|
10 |
-
var $this = $( this );
|
11 |
-
var data = {
|
12 |
-
action: wpc.action_prefix + 'add_condition',
|
13 |
-
group: $( this ).attr( 'data-group' ),
|
14 |
-
nonce: wpc.nonce
|
15 |
-
};
|
16 |
-
var condition_group = $this.parents( '.wpc-conditions' ).find( '.wpc-condition-group-' + data.group );
|
17 |
-
|
18 |
-
var loading_icon = '<div class="wpc-condition-wrap loading"></div>';
|
19 |
-
condition_group.append( loading_icon ).children( ':last' ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } });
|
20 |
-
|
21 |
-
$.post( ajaxurl, data, function( response ) {
|
22 |
-
condition_group.find( ' .wpc-condition-wrap.loading' ).first().replaceWith( function() {
|
23 |
-
return $( response ).hide().fadeIn( 'normal' );
|
24 |
-
});
|
25 |
-
});
|
26 |
-
|
27 |
-
});
|
28 |
-
|
29 |
-
// Delete condition
|
30 |
-
$( document.body ).on( 'click', '.wpc-condition-delete', function() {
|
31 |
-
|
32 |
-
if ( $( this ).closest( '.wpc-condition-group' ).children( '.wpc-condition-wrap' ).length == 1 ) {
|
33 |
-
$( this ).closest( '.wpc-condition-group' ).fadeOut( 'normal', function() {
|
34 |
-
$( this ).next( '.or-text' ).remove();
|
35 |
-
$( this ).remove();
|
36 |
-
});
|
37 |
-
} else {
|
38 |
-
$( this ).closest( '.wpc-condition-wrap' ).slideUp( 'fast', function() { $( this ).remove(); });
|
39 |
-
}
|
40 |
-
|
41 |
-
});
|
42 |
-
|
43 |
-
// Add condition group
|
44 |
-
$( document.body ).on( 'click', '.wpc-condition-group-add', function() {
|
45 |
-
|
46 |
-
var condition_group_loading = '<div class="wpc-condition-group loading"></div>';
|
47 |
-
var conditions = $( this ).prev( '.wpc-conditions' );
|
48 |
-
var data = {
|
49 |
-
action: wpc.action_prefix + 'add_condition_group',
|
50 |
-
group: parseInt( $( this ).prev( '.wpc-conditions' ).find( '.wpc-condition-group' ).length ),
|
51 |
-
nonce: wpc.nonce
|
52 |
-
};
|
53 |
-
|
54 |
-
// Display loading icon
|
55 |
-
conditions.append( condition_group_loading ).children( ':last' ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } });
|
56 |
-
|
57 |
-
// Insert condition group
|
58 |
-
$.post( ajaxurl, data, function( response ) {
|
59 |
-
conditions.find( '.wpc-condition-group.loading' ).first().replaceWith( function() {
|
60 |
-
return $( response ).hide().fadeIn( 'normal' );
|
61 |
-
});
|
62 |
-
});
|
63 |
-
|
64 |
-
});
|
65 |
-
|
66 |
-
// Update condition values
|
67 |
-
$( document.body ).on( 'change', '.wpc-condition', function () {
|
68 |
-
|
69 |
-
var loading_wrap = '<span style="width: 30%; border: 1px solid transparent; display: inline-block;"> </span>';
|
70 |
-
var data = {
|
71 |
-
action: wpc.action_prefix + 'update_condition_value',
|
72 |
-
id: $( this ).attr( 'data-id' ),
|
73 |
-
group: $( this ).attr( 'data-group' ),
|
74 |
-
condition: $( this ).val(),
|
75 |
-
nonce: wpc.nonce
|
76 |
-
};
|
77 |
-
var condition_group = $( this ).parents( '.wpc-conditions' ).find( '.wpc-condition-group-' + data.group );
|
78 |
-
var replace = '.wpc-value-wrap-' + data.id;
|
79 |
-
|
80 |
-
// Loading icon
|
81 |
-
condition_group.find( replace ).html( loading_wrap ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } });
|
82 |
-
|
83 |
-
// Replace value field
|
84 |
-
$.post( ajaxurl, data, function( response ) {
|
85 |
-
condition_group.find( replace ).replaceWith( response );
|
86 |
-
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
87 |
-
});
|
88 |
-
|
89 |
-
// Update condition description
|
90 |
-
var description = {
|
91 |
-
action: wpc.action_prefix + 'update_condition_description',
|
92 |
-
condition: data.condition,
|
93 |
-
nonce: wpc.nonce
|
94 |
-
};
|
95 |
-
|
96 |
-
$.post( ajaxurl, description, function( description_response ) {
|
97 |
-
condition_group.find( replace + ' ~ .wpc-description' ).replaceWith( description_response );
|
98 |
-
// Tooltip
|
99 |
-
$( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 200 });
|
100 |
-
})
|
101 |
-
|
102 |
-
});
|
103 |
-
|
104 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/js/woocommerce-advanced-free-shipping.min.js
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
jQuery(function($){$(document.body).on("click",".wpc-condition-add",function(){var n=$(this),o={action:wpc.action_prefix+"add_condition",group:$(this).attr("data-group"),nonce:wpc.nonce},i=n.parents(".wpc-conditions").find(".wpc-condition-group-"+o.group),t='<div class="wpc-condition-wrap loading"></div>';i.append(t).children(":last").block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,o,function(n){i.find(" .wpc-condition-wrap.loading").first().replaceWith(function(){return $(n).hide().fadeIn("normal")})})}),$(document.body).on("click",".wpc-condition-delete",function(){1==$(this).closest(".wpc-condition-group").children(".wpc-condition-wrap").length?$(this).closest(".wpc-condition-group").fadeOut("normal",function(){$(this).next(".or-text").remove(),$(this).remove()}):$(this).closest(".wpc-condition-wrap").slideUp("fast",function(){$(this).remove()})}),$(document.body).on("click",".wpc-condition-group-add",function(){var n='<div class="wpc-condition-group loading"></div>',o=$(this).prev(".wpc-conditions"),i={action:wpc.action_prefix+"add_condition_group",group:parseInt($(this).prev(".wpc-conditions").find(".wpc-condition-group").length),nonce:wpc.nonce};o.append(n).children(":last").block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,i,function(n){o.find(".wpc-condition-group.loading").first().replaceWith(function(){return $(n).hide().fadeIn("normal")})})}),$(document.body).on("change",".wpc-condition",function(){var n='<span style="width: 30%; border: 1px solid transparent; display: inline-block;"> </span>',o={action:wpc.action_prefix+"update_condition_value",id:$(this).attr("data-id"),group:$(this).attr("data-group"),condition:$(this).val(),nonce:wpc.nonce},i=$(this).parents(".wpc-conditions").find(".wpc-condition-group-"+o.group),t=".wpc-value-wrap-"+o.id;i.find(t).html(n).block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,o,function(n){i.find(t).replaceWith(n),$(document.body).trigger("wc-enhanced-select-init")});var c={action:wpc.action_prefix+"update_condition_description",condition:o.condition,nonce:wpc.nonce};$.post(ajaxurl,c,function(n){i.find(t+" ~ .wpc-description").replaceWith(n),$(".tips, .help_tip, .woocommerce-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})})})});
|
|
codeoversight.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
php:
|
2 |
align_array_elements: space
|
3 |
-
align_doc_tags:
|
4 |
align_variables: space
|
5 |
closing_newline: add
|
6 |
closing_php_tag: remove
|
@@ -26,14 +26,18 @@ php:
|
|
26 |
type_cast_inner_whitespace: no_space
|
27 |
use_quotes: single_quotes
|
28 |
variable_array_index_whitespace: whitespace
|
29 |
-
whitespace_after_control_structure: whitespace
|
30 |
whitespace_after_doc_asterisk: single_space
|
31 |
whitespace_after_else: space
|
32 |
whitespace_after_function_open: newline
|
33 |
whitespace_after_function: double_newline
|
34 |
whitespace_before_control_structure_brace: space
|
|
|
35 |
whitespace_before_doc_asterisk: space
|
36 |
whitespace_before_else: space
|
37 |
whitespace_before_function_brace: space
|
38 |
whitespace_before_function_close: newline
|
39 |
whitespace_before_function_parentheses: no_space
|
|
|
|
|
|
|
|
1 |
php:
|
2 |
align_array_elements: space
|
3 |
+
align_doc_tags: space
|
4 |
align_variables: space
|
5 |
closing_newline: add
|
6 |
closing_php_tag: remove
|
26 |
type_cast_inner_whitespace: no_space
|
27 |
use_quotes: single_quotes
|
28 |
variable_array_index_whitespace: whitespace
|
|
|
29 |
whitespace_after_doc_asterisk: single_space
|
30 |
whitespace_after_else: space
|
31 |
whitespace_after_function_open: newline
|
32 |
whitespace_after_function: double_newline
|
33 |
whitespace_before_control_structure_brace: space
|
34 |
+
whitespace_before_control_structure_parentheses: whitespace
|
35 |
whitespace_before_doc_asterisk: space
|
36 |
whitespace_before_else: space
|
37 |
whitespace_before_function_brace: space
|
38 |
whitespace_before_function_close: newline
|
39 |
whitespace_before_function_parentheses: no_space
|
40 |
+
|
41 |
+
blacklist:
|
42 |
+
directories:
|
43 |
+
- libraries
|
includes/admin/admin-functions.php
DELETED
@@ -1,100 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
-
|
4 |
-
if ( ! function_exists( 'wpc_html_field' ) ) {
|
5 |
-
|
6 |
-
/**
|
7 |
-
* Output html field.
|
8 |
-
*
|
9 |
-
* Output a new HTML field.
|
10 |
-
*
|
11 |
-
* @since 1.1.6
|
12 |
-
*
|
13 |
-
* @param array $args
|
14 |
-
*/
|
15 |
-
function wpc_html_field( $args = array() ) {
|
16 |
-
|
17 |
-
$args = wp_parse_args( $args, array(
|
18 |
-
'id' => '',
|
19 |
-
'type' => 'text',
|
20 |
-
'name' => '',
|
21 |
-
'class' => '',
|
22 |
-
'value' => null,
|
23 |
-
'default' => '',
|
24 |
-
'placeholder' => '',
|
25 |
-
'custom_attributes' => isset( $args['custom_attr'] ) ? $args['custom_attr'] : array(), // BC
|
26 |
-
) );
|
27 |
-
|
28 |
-
$type = ! empty( $args['field'] ) ? $args['field'] : $args['type'];
|
29 |
-
$class = is_array( $args['class'] ) ? implode( ' ', array_map( 'sanitize_html_class', $args['class'] ) ) : sanitize_html_class( $args['class'] );
|
30 |
-
$value = isset( $args['value'] ) ? $args['value'] : '';
|
31 |
-
$name = isset( $args['name'] ) ? $args['name'] : $args['id'];
|
32 |
-
$custom_attributes = array();
|
33 |
-
if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) {
|
34 |
-
foreach ( $args['custom_attributes'] as $k => $v ) {
|
35 |
-
$custom_attributes[ $k ] = esc_attr( $k ) . '="' . esc_attr( $v ) . '"';
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
-
switch ( $type ) :
|
40 |
-
|
41 |
-
case 'text' :
|
42 |
-
case 'number' :
|
43 |
-
?><input
|
44 |
-
name="<?php echo esc_attr( $name ); ?>"
|
45 |
-
type="<?php echo $args['type']; ?>"
|
46 |
-
id="<?php echo esc_attr( $args['id'] ); ?>"
|
47 |
-
value="<?php echo esc_attr( $value ); ?>"
|
48 |
-
class="input-text <?php echo $class; ?>"
|
49 |
-
<?php echo implode( ' ', $custom_attributes ); ?>
|
50 |
-
placeholder='<?php echo esc_attr( $args['placeholder'] ); ?>'
|
51 |
-
><?php
|
52 |
-
break;
|
53 |
-
|
54 |
-
case 'dropdown' :
|
55 |
-
case 'select' :
|
56 |
-
|
57 |
-
$options = is_array( $args['options'] ) ? $args['options'] : array();
|
58 |
-
|
59 |
-
?><select
|
60 |
-
name="<?php echo esc_attr( $args['name'] ); ?>"
|
61 |
-
id="<?php echo esc_attr( $args['id'] ); ?>"
|
62 |
-
class="input-select <?php echo $class; ?>"
|
63 |
-
<?php echo implode( ' ', $custom_attributes ); ?>
|
64 |
-
><?php
|
65 |
-
|
66 |
-
foreach ( $options as $index => $values ) :
|
67 |
-
|
68 |
-
if ( ! is_array( $values ) ) :
|
69 |
-
?><option value='<?php echo esc_attr( $index ); ?>' <?php selected( $index, $value ); ?>><?php echo esc_attr( $values ); ?></option><?php
|
70 |
-
else :
|
71 |
-
?><optgroup label='<?php echo esc_attr( $index ); ?>'><?php
|
72 |
-
foreach ( $values as $k => $v ) :
|
73 |
-
?><option value='<?php echo esc_attr( $k ); ?>' <?php selected( $k, $value ); ?>><?php echo esc_attr( $v ); ?></option><?php
|
74 |
-
endforeach;
|
75 |
-
?></optgroup><?php
|
76 |
-
endif;
|
77 |
-
|
78 |
-
endforeach;
|
79 |
-
|
80 |
-
if ( empty( $options ) ) :
|
81 |
-
?><option readonly disabled><?php
|
82 |
-
_e( 'There are no options available', 'woocommerce-advanced-fees' );
|
83 |
-
?></option><?php
|
84 |
-
endif;
|
85 |
-
|
86 |
-
?></select><?php
|
87 |
-
break;
|
88 |
-
|
89 |
-
default :
|
90 |
-
case 'hook' :
|
91 |
-
|
92 |
-
do_action( 'woocommerce_advanced_fees_condition_value_field_type_' . $args['type'], $args );
|
93 |
-
break;
|
94 |
-
|
95 |
-
endswitch;
|
96 |
-
|
97 |
-
}
|
98 |
-
|
99 |
-
|
100 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/admin/class-wafs-admin.php
CHANGED
@@ -18,12 +18,7 @@ class WAFS_Admin {
|
|
18 |
*
|
19 |
* @since 1.0.8
|
20 |
*/
|
21 |
-
public function __construct() {
|
22 |
-
|
23 |
-
// Initialize plugin parts
|
24 |
-
add_action( 'admin_init', array( $this, 'init' ) );
|
25 |
-
|
26 |
-
}
|
27 |
|
28 |
|
29 |
/**
|
@@ -44,7 +39,6 @@ class WAFS_Admin {
|
|
44 |
|
45 |
global $pagenow;
|
46 |
if ( 'plugins.php' == $pagenow ) :
|
47 |
-
// Plugins page
|
48 |
add_filter( 'plugin_action_links_' . plugin_basename( WAFS()->file ), array( $this, 'add_plugin_action_links' ), 10, 2 );
|
49 |
endif;
|
50 |
|
@@ -64,10 +58,8 @@ class WAFS_Admin {
|
|
64 |
|
65 |
wp_register_style( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/css/woocommerce-advanced-free-shipping.min.css', WAFS()->file ), array(), WAFS()->version );
|
66 |
wp_register_script( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/js/woocommerce-advanced-free-shipping' . $suffix . '.js', WAFS()->file ), array( 'jquery' ), WAFS()->version, true );
|
67 |
-
wp_localize_script( 'woocommerce-advanced-free-shipping', '
|
68 |
-
'nonce'
|
69 |
-
'action_prefix' => 'wafs_',
|
70 |
-
'asset_url' => plugins_url( 'assets/', WAFS()->file ),
|
71 |
) );
|
72 |
|
73 |
if (
|
@@ -76,8 +68,14 @@ class WAFS_Admin {
|
|
76 |
( isset( $_REQUEST['section'] ) && 'advanced_free_shipping' == $_REQUEST['section'] )
|
77 |
) :
|
78 |
|
|
|
|
|
|
|
|
|
79 |
wp_enqueue_style( 'woocommerce-advanced-free-shipping' );
|
80 |
wp_enqueue_script( 'woocommerce-advanced-free-shipping' );
|
|
|
|
|
81 |
wp_dequeue_script( 'autosave' );
|
82 |
|
83 |
endif;
|
18 |
*
|
19 |
* @since 1.0.8
|
20 |
*/
|
21 |
+
public function __construct() {}
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
/**
|
39 |
|
40 |
global $pagenow;
|
41 |
if ( 'plugins.php' == $pagenow ) :
|
|
|
42 |
add_filter( 'plugin_action_links_' . plugin_basename( WAFS()->file ), array( $this, 'add_plugin_action_links' ), 10, 2 );
|
43 |
endif;
|
44 |
|
58 |
|
59 |
wp_register_style( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/css/woocommerce-advanced-free-shipping.min.css', WAFS()->file ), array(), WAFS()->version );
|
60 |
wp_register_script( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/js/woocommerce-advanced-free-shipping' . $suffix . '.js', WAFS()->file ), array( 'jquery' ), WAFS()->version, true );
|
61 |
+
wp_localize_script( 'woocommerce-advanced-free-shipping', 'wafs', array(
|
62 |
+
'nonce' => wp_create_nonce( 'wpc-ajax-nonce' ),
|
|
|
|
|
63 |
) );
|
64 |
|
65 |
if (
|
68 |
( isset( $_REQUEST['section'] ) && 'advanced_free_shipping' == $_REQUEST['section'] )
|
69 |
) :
|
70 |
|
71 |
+
wp_localize_script( 'wp-conditions', 'wpc2', array(
|
72 |
+
'action_prefix' => 'wafs_',
|
73 |
+
) );
|
74 |
+
|
75 |
wp_enqueue_style( 'woocommerce-advanced-free-shipping' );
|
76 |
wp_enqueue_script( 'woocommerce-advanced-free-shipping' );
|
77 |
+
wp_enqueue_script( 'wp-conditions' );
|
78 |
+
|
79 |
wp_dequeue_script( 'autosave' );
|
80 |
|
81 |
endif;
|
includes/admin/class-wafs-condition.php
CHANGED
@@ -58,7 +58,7 @@ class WAFS_Condition {
|
|
58 |
*
|
59 |
* @since 1.0.0
|
60 |
*/
|
61 |
-
public function __construct( $id = null, $group = 0, $condition =
|
62 |
|
63 |
$this->id = $id;
|
64 |
$this->group = $group;
|
@@ -144,17 +144,8 @@ class WAFS_Condition {
|
|
144 |
* @return array List of available operators.
|
145 |
*/
|
146 |
public function get_operators() {
|
147 |
-
|
148 |
-
|
149 |
-
'==' => __( 'Equal to', 'woocommerce-advanced-free-shipping' ),
|
150 |
-
'!=' => __( 'Not equal to', 'woocommerce-advanced-free-shipping' ),
|
151 |
-
'>=' => __( 'Greater or equal to', 'woocommerce-advanced-free-shipping' ),
|
152 |
-
'<=' => __( 'Less or equal to ', 'woocommerce-advanced-free-shipping' ),
|
153 |
-
);
|
154 |
-
$operators = apply_filters( 'wafs_operators', $operators );
|
155 |
-
|
156 |
-
return $operators;
|
157 |
-
|
158 |
}
|
159 |
|
160 |
|
@@ -171,150 +162,27 @@ class WAFS_Condition {
|
|
171 |
public function get_value_field_args() {
|
172 |
|
173 |
// Defaults
|
174 |
-
$
|
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 |
-
|
184 |
-
|
185 |
-
default:
|
186 |
-
case 'subtotal' :
|
187 |
-
case 'subtotal_ex_tax' :
|
188 |
-
case 'tax' :
|
189 |
-
case 'quantity' :
|
190 |
-
case 'coupon' :
|
191 |
-
case 'weight' :
|
192 |
-
$values['type'] = 'text';
|
193 |
-
break;
|
194 |
-
|
195 |
-
case 'contains_product' :
|
196 |
-
|
197 |
-
$product = wc_get_product( $this->value );
|
198 |
-
if ( $product ) {
|
199 |
-
$values['custom_attributes']['data-selected'] = $product->get_formatted_name();
|
200 |
-
}
|
201 |
-
|
202 |
-
$values['type'] = 'text';
|
203 |
-
$values['placeholder'] = __( 'Search for a product', 'woocommerce-advanced-messages' );
|
204 |
-
$values['class'][] = 'wc-product-search';
|
205 |
-
|
206 |
-
break;
|
207 |
-
|
208 |
-
case 'contains_shipping_class' :
|
209 |
-
|
210 |
-
$values['type'] = 'select';
|
211 |
-
$values['options'][''] = __( 'No shipping class', 'woocommerce' );
|
212 |
-
|
213 |
-
// Get all shipping classes
|
214 |
-
foreach ( get_terms( 'product_shipping_class', array( 'hide_empty' => false ) ) as $shipping_class ) :
|
215 |
-
$values['options'][ $shipping_class->slug ] = $shipping_class->name;
|
216 |
-
endforeach;
|
217 |
-
|
218 |
-
break;
|
219 |
-
|
220 |
-
/**
|
221 |
-
* User details
|
222 |
-
*/
|
223 |
-
|
224 |
-
case 'zipcode' :
|
225 |
-
case 'city' :
|
226 |
-
$values['type'] = 'text';
|
227 |
-
break;
|
228 |
-
|
229 |
-
case 'state' :
|
230 |
-
|
231 |
-
$values['type'] = 'select';
|
232 |
-
$values['class'][] = 'wc-enhanced-select';
|
233 |
-
|
234 |
-
$country_states = array();
|
235 |
-
foreach ( WC()->countries->states as $country => $states ) :
|
236 |
-
|
237 |
-
if ( empty( $states ) ) continue; // Don't show country if it has no states
|
238 |
-
if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries
|
239 |
-
|
240 |
-
foreach ( $states as $state_key => $state ) :
|
241 |
-
$country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state;
|
242 |
-
endforeach;
|
243 |
-
|
244 |
-
$values['options'] = $country_states;
|
245 |
-
|
246 |
-
endforeach;
|
247 |
-
|
248 |
-
break;
|
249 |
-
|
250 |
-
case 'country' :
|
251 |
-
|
252 |
-
$values['field'] = 'select';
|
253 |
-
$values['class'][] = 'wc-enhanced-select';
|
254 |
-
|
255 |
-
$countries = WC()->countries->get_allowed_countries() + WC()->countries->get_shipping_countries();
|
256 |
-
$continents = array();
|
257 |
-
if ( method_exists( WC()->countries, 'get_continents' ) ) :
|
258 |
-
foreach ( WC()->countries->get_continents() as $k => $v ) :
|
259 |
-
$continents[ 'CO_' . $k ] = $v['name']; // Add prefix for country key compatibility
|
260 |
-
endforeach;
|
261 |
-
endif;
|
262 |
-
|
263 |
-
if ( $continents ) {
|
264 |
-
$values['options'][ __( 'Continents', 'woocommerce' ) ] = $continents;
|
265 |
-
}
|
266 |
-
$values['options'][ __( 'Countries', 'woocommerce' ) ] = $countries;
|
267 |
-
|
268 |
-
break;
|
269 |
-
|
270 |
-
case 'role' :
|
271 |
-
$values['type'] = 'select';
|
272 |
-
$roles = array_keys( get_editable_roles() );
|
273 |
-
$values['options'] = array_combine( $roles, $roles );
|
274 |
-
break;
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Product
|
278 |
-
*/
|
279 |
-
|
280 |
-
case 'width' :
|
281 |
-
case 'height' :
|
282 |
-
case 'length' :
|
283 |
-
case 'stock' :
|
284 |
-
$values['type'] = 'text';
|
285 |
-
break;
|
286 |
-
|
287 |
-
case 'stock_status' :
|
288 |
-
|
289 |
-
$values['type'] = 'select';
|
290 |
-
$values['options'] = array(
|
291 |
-
'instock' => __( 'In stock', 'woocommerce-advanced-free-shipping' ),
|
292 |
-
'outofstock' => __( 'Out of stock', 'woocommerce-advanced-free-shipping' ),
|
293 |
-
);
|
294 |
-
|
295 |
-
break;
|
296 |
-
|
297 |
-
case 'category' :
|
298 |
-
|
299 |
-
$values['type'] = 'select';
|
300 |
-
$values['class'][] = 'wc-enhanced-select';
|
301 |
-
|
302 |
-
$categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
|
303 |
-
foreach ( $categories as $category ) :
|
304 |
-
$values['options'][ $category->slug ] = $category->name;
|
305 |
-
endforeach;
|
306 |
-
|
307 |
-
break;
|
308 |
-
|
309 |
-
|
310 |
-
endswitch;
|
311 |
-
|
312 |
-
$values = apply_filters( 'wafs_values', $values, $this->condition );
|
313 |
-
|
314 |
-
|
315 |
-
$values = apply_filters( 'woocommerce_advanced_free_shipping_values', $values, $this->condition );
|
316 |
|
317 |
-
return $
|
318 |
|
319 |
}
|
320 |
|
@@ -327,23 +195,8 @@ class WAFS_Condition {
|
|
327 |
* @since 1.0.0
|
328 |
*/
|
329 |
public function get_description() {
|
330 |
-
|
331 |
-
$descriptions = array(
|
332 |
-
'state' => __( 'States must be installed in WC.', 'woocommerce-advanced-free-shipping' ),
|
333 |
-
'weight' => __( 'Weight calculated on all the cart contents', 'woocommerce-advanced-free-shipping' ),
|
334 |
-
'length' => __( 'Compared to lengthiest product in cart', 'woocommerce-advanced-free-shipping' ),
|
335 |
-
'width' => __( 'Compared to widest product in cart', 'woocommerce-advanced-free-shipping' ),
|
336 |
-
'height' => __( 'Compared to highest product in cart', 'woocommerce-advanced-free-shipping' ),
|
337 |
-
'stock_status' => __( 'All products in cart must match stock status', 'woocommerce-advanced-free-shipping' ),
|
338 |
-
'category' => __( 'All products in cart must match category', 'woocommerce-advanced-free-shipping' ),
|
339 |
-
'contains_product' => __( 'Cart must contain one of this product', 'woocommerce-advanced-free-shipping' ),
|
340 |
-
'contains_shipping_class' => __( 'Cart must contain at least one product with the selected shipping class', 'woocommerce-advanced-free-shipping' ),
|
341 |
-
);
|
342 |
-
|
343 |
-
$descriptions = apply_filters( 'wafs_descriptions', $descriptions );
|
344 |
-
|
345 |
return isset( $descriptions[ $this->condition ] ) ? $descriptions[ $this->condition ] : '';
|
346 |
-
|
347 |
}
|
348 |
|
349 |
|
58 |
*
|
59 |
* @since 1.0.0
|
60 |
*/
|
61 |
+
public function __construct( $id = null, $group = 0, $condition = 'subtotal', $operator = null, $value = null ) {
|
62 |
|
63 |
$this->id = $id;
|
64 |
$this->group = $group;
|
144 |
* @return array List of available operators.
|
145 |
*/
|
146 |
public function get_operators() {
|
147 |
+
$wpc_condition = wpc_get_condition( $this->condition );
|
148 |
+
return apply_filters( 'woocommerce_Advanced_Shipping_Validation_operators', $wpc_condition->get_available_operators() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
}
|
150 |
|
151 |
|
162 |
public function get_value_field_args() {
|
163 |
|
164 |
// Defaults
|
165 |
+
$default_field_args = array(
|
166 |
'name' => 'conditions[' . absint( $this->group ) . '][' . absint( $this->id ) . '][value]',
|
167 |
'placeholder' => '',
|
168 |
'type' => 'text',
|
169 |
+
'class' => array( 'wpc-value' ),
|
170 |
);
|
171 |
|
172 |
+
$field_args = $default_field_args;
|
173 |
+
if ( $condition = wpc_get_condition( $this->condition ) ) {
|
174 |
+
$field_args = wp_parse_args( $condition->get_value_field_args(), $field_args );
|
175 |
+
}
|
176 |
|
177 |
+
if ( $this->condition == 'contains_product' && $product = wc_get_product( $this->value ) ) {
|
178 |
+
$field_args['custom_attributes']['data-selected'] = $product->get_formatted_name(); // WC < 2.7
|
179 |
+
$field_args['options'][ $this->value ] = $product->get_formatted_name(); // WC >= 2.7
|
180 |
+
}
|
181 |
|
182 |
+
$field_args = apply_filters( 'wafs_values', $field_args, $this->condition );
|
183 |
+
$field_args = apply_filters( 'woocommerce_advanced_free_shipping_values', $field_args, $this->condition );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
+
return $field_args;
|
186 |
|
187 |
}
|
188 |
|
195 |
* @since 1.0.0
|
196 |
*/
|
197 |
public function get_description() {
|
198 |
+
$descriptions = apply_filters( 'wafs_descriptions', wpc_condition_descriptions() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
return isset( $descriptions[ $this->condition ] ) ? $descriptions[ $this->condition ] : '';
|
|
|
200 |
}
|
201 |
|
202 |
|
includes/admin/views/conditions-table.php
CHANGED
@@ -19,7 +19,7 @@ $shipping_rates = wafs_get_rates( array( 'post_status' => array( 'draft', 'publi
|
|
19 |
</th>
|
20 |
<td class="forminp" id="<?php echo $this->id; ?>_shipping_methods">
|
21 |
|
22 |
-
<table class='wp-list-table wpc-conditions-post-table widefat'>
|
23 |
<thead>
|
24 |
<tr>
|
25 |
<th style='padding-left: 10px;'><?php _e( 'Title', 'woocommerce-advanced-free-shipping' ); ?></th>
|
19 |
</th>
|
20 |
<td class="forminp" id="<?php echo $this->id; ?>_shipping_methods">
|
21 |
|
22 |
+
<table class='wp-list-table wpc-conditions-post-table wpc-sortable-post-table widefat'>
|
23 |
<thead>
|
24 |
<tr>
|
25 |
<th style='padding-left: 10px;'><?php _e( 'Title', 'woocommerce-advanced-free-shipping' ); ?></th>
|
includes/admin/views/html-condition-group.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
?><div class='wpc-condition-group-wrap'>
|
5 |
+
<p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p>
|
6 |
+
|
7 |
+
<div class='wpc-condition-group clearfix' data-group='<?php echo absint( $condition_group ); ?>'>
|
8 |
+
|
9 |
+
<span class='wpc-condition-group-actions alignright'>
|
10 |
+
<a href='javascript:void(0);' class='duplicate'><?php _e( 'Duplicate', 'woocommerce-advanced-free-shipping' ); ?></a> | <a href='javascript:void(0);' class='delete'><?php _e( 'Delete', 'woocommerce-advanced-free-shipping' ); ?></a>
|
11 |
+
</span>
|
12 |
+
<p class='match-text'><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p>
|
13 |
+
|
14 |
+
<div class='wpc-conditions-list'><?php
|
15 |
+
|
16 |
+
if ( ! empty( $conditions ) ) :
|
17 |
+
|
18 |
+
foreach ( $conditions as $condition_id => $condition ) :
|
19 |
+
$wp_condition = new WAFS_Condition( $condition_id, $condition_group, $condition['condition'], $condition['operator'], $condition['value'] );
|
20 |
+
$wp_condition->output_condition_row();
|
21 |
+
endforeach;
|
22 |
+
|
23 |
+
else :
|
24 |
+
|
25 |
+
$wp_condition = new WAFS_Condition( null, $condition_group );
|
26 |
+
$wp_condition->output_condition_row();
|
27 |
+
|
28 |
+
endif;
|
29 |
+
|
30 |
+
?></div>
|
31 |
+
|
32 |
+
<div class="wpc-condition-template hidden" style="display: none;"><?php
|
33 |
+
$wp_condition = new WAFS_Condition( '9999', $condition_group );
|
34 |
+
$wp_condition->output_condition_row();
|
35 |
+
?></div>
|
36 |
+
<a style="margin-top: 0.5em; margin-right: 63px;" class='wpc-condition-add wpc-add button alignright' data-group='<?php echo absint( $condition_group ); ?>' href='javascript:void(0);'><?php _e( 'Add condition', 'woocommerce-advanced-free-shipping' ); ?></a>
|
37 |
+
|
38 |
+
</div>
|
39 |
+
</div>
|
includes/admin/views/html-condition-row.php
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
<?php
|
2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
|
|
|
|
|
4 |
?><div class='wpc-condition-wrap'>
|
5 |
|
6 |
<!-- Condition -->
|
7 |
-
<span class='wpc-condition-
|
8 |
|
9 |
$condition_field_args = array(
|
10 |
'type' => 'select',
|
@@ -13,8 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
13 |
'options' => $wp_condition->get_conditions(),
|
14 |
'value' => $wp_condition->condition,
|
15 |
'custom_attr' => array(
|
16 |
-
'data-
|
17 |
-
'data-id' => absint( $wp_condition->id ),
|
18 |
),
|
19 |
);
|
20 |
wpc_html_field( $condition_field_args );
|
@@ -23,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
23 |
|
24 |
|
25 |
<!-- Operator -->
|
26 |
-
<span class='wpc-operator-
|
27 |
|
28 |
$operator_field_args = array(
|
29 |
'type' => 'select',
|
@@ -38,24 +39,23 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
38 |
|
39 |
|
40 |
<!-- Value -->
|
41 |
-
<span class='wpc-value-
|
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 |
-
|
48 |
-
<a class='button wpc-condition-
|
49 |
-
<a class='button wpc-condition-delete' href='javascript:void(0);'>-</a><?php
|
50 |
|
51 |
|
52 |
// Description
|
53 |
if ( $desc = $wp_condition->get_description() ) :
|
54 |
-
?><span class='wpc-description
|
55 |
-
<
|
56 |
</span><?php
|
57 |
else :
|
58 |
-
?><span class='wpc-description wpc-no-description
|
59 |
endif;
|
60 |
|
61 |
?></div>
|
1 |
<?php
|
2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
|
4 |
+
$condition = wpc_get_condition( $wp_condition->condition );
|
5 |
+
|
6 |
?><div class='wpc-condition-wrap'>
|
7 |
|
8 |
<!-- Condition -->
|
9 |
+
<span class='wpc-condition-field-wrap'><?php
|
10 |
|
11 |
$condition_field_args = array(
|
12 |
'type' => 'select',
|
15 |
'options' => $wp_condition->get_conditions(),
|
16 |
'value' => $wp_condition->condition,
|
17 |
'custom_attr' => array(
|
18 |
+
'data-id' => absint( $wp_condition->id ),
|
|
|
19 |
),
|
20 |
);
|
21 |
wpc_html_field( $condition_field_args );
|
24 |
|
25 |
|
26 |
<!-- Operator -->
|
27 |
+
<span class='wpc-operator-field-wrap'><?php
|
28 |
|
29 |
$operator_field_args = array(
|
30 |
'type' => 'select',
|
39 |
|
40 |
|
41 |
<!-- Value -->
|
42 |
+
<span class='wpc-value-field-wrap'><?php
|
43 |
$value_field_args = wp_parse_args( array( 'value' => $wp_condition->value ), $wp_condition->get_value_field_args() );
|
44 |
wpc_html_field( $value_field_args );
|
45 |
?></span>
|
46 |
|
47 |
|
48 |
+
<!-- Delete-->
|
49 |
+
<a class='button wpc-condition-delete' href='javascript:void(0);'></a><?php
|
|
|
50 |
|
51 |
|
52 |
// Description
|
53 |
if ( $desc = $wp_condition->get_description() ) :
|
54 |
+
?><span class='wpc-description'>
|
55 |
+
<span class="woocommerce-help-tip" data-tip="<?php echo wp_kses_post( $desc ); ?>"></span>
|
56 |
</span><?php
|
57 |
else :
|
58 |
+
?><span class='wpc-description wpc-no-description'><?php
|
59 |
endif;
|
60 |
|
61 |
?></div>
|
includes/admin/views/meta-box-conditions.php
CHANGED
@@ -7,37 +7,27 @@ $condition_groups = get_post_meta( $post->ID, '_wafs_shipping_method_conditions'
|
|
7 |
?><div class='wpc-conditions wpc-conditions-meta-box'>
|
8 |
|
9 |
<p>
|
10 |
-
<strong><?php _e( 'Match
|
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 |
-
|
35 |
-
|
36 |
-
$wp_condition->output_condition_row();
|
37 |
-
?></div><?php
|
38 |
|
39 |
endif;
|
40 |
|
41 |
-
|
42 |
|
|
|
|
|
|
|
|
|
|
|
43 |
<a class='button wpc-condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'woocommerce-advanced-free-shipping' ); ?></a>
|
7 |
?><div class='wpc-conditions wpc-conditions-meta-box'>
|
8 |
|
9 |
<p>
|
10 |
+
<strong><?php _e( 'Match one of the condition groups to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong>
|
11 |
</p><?php
|
12 |
|
13 |
if ( ! empty( $condition_groups ) ) :
|
14 |
|
15 |
foreach ( $condition_groups as $condition_group => $conditions ) :
|
16 |
+
include plugin_dir_path( __FILE__ ) . 'html-condition-group.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
endforeach;
|
18 |
|
19 |
else :
|
20 |
|
21 |
+
$condition_group = '0';
|
22 |
+
include plugin_dir_path( __FILE__ ) . 'html-condition-group.php';
|
|
|
|
|
23 |
|
24 |
endif;
|
25 |
|
26 |
+
?></div>
|
27 |
|
28 |
+
<div class='wpc-condition-group-template hidden' style='display: none'><?php
|
29 |
+
$condition_group = '9999';
|
30 |
+
$conditions = array();
|
31 |
+
include plugin_dir_path( __FILE__ ) . 'html-condition-group.php';
|
32 |
+
?></div>
|
33 |
<a class='button wpc-condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'woocommerce-advanced-free-shipping' ); ?></a>
|
includes/admin/views/meta-box-settings.php
CHANGED
@@ -32,5 +32,4 @@ $settings['shipping_title'] = ! empty( $settings['shipping_title'] ) ? $settings
|
|
32 |
|
33 |
</p>
|
34 |
|
35 |
-
|
36 |
</div>
|
32 |
|
33 |
</p>
|
34 |
|
|
|
35 |
</div>
|
includes/class-wafs-ajax.php
CHANGED
@@ -19,60 +19,8 @@ class WAFS_Ajax {
|
|
19 |
*/
|
20 |
public function __construct() {
|
21 |
|
22 |
-
// Add elements
|
23 |
-
add_action( 'wp_ajax_wafs_add_condition', array( $this, 'add_condition' ) );
|
24 |
-
add_action( 'wp_ajax_wafs_add_condition_group', array( $this, 'add_condition_group' ) );
|
25 |
-
|
26 |
// Update elements
|
27 |
add_action( 'wp_ajax_wafs_update_condition_value', array( $this, 'update_condition_value' ) );
|
28 |
-
add_action( 'wp_ajax_wafs_update_condition_description', array( $this, 'update_condition_description' ) );
|
29 |
-
|
30 |
-
}
|
31 |
-
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Add condition.
|
35 |
-
*
|
36 |
-
* Output the HTML of a new condition row.
|
37 |
-
*
|
38 |
-
* @since 1.0.0
|
39 |
-
*/
|
40 |
-
public function add_condition() {
|
41 |
-
|
42 |
-
check_ajax_referer( 'wpc-ajax-nonce', 'nonce' );
|
43 |
-
|
44 |
-
$wp_condition = new WAFS_Condition( null, $_POST['group'] );
|
45 |
-
$wp_condition->output_condition_row();
|
46 |
-
|
47 |
-
die();
|
48 |
-
|
49 |
-
}
|
50 |
-
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Condition group.
|
54 |
-
*
|
55 |
-
* Output the HTML of a new condition group.
|
56 |
-
*
|
57 |
-
* @since 1.0.0
|
58 |
-
*/
|
59 |
-
public function add_condition_group() {
|
60 |
-
|
61 |
-
check_ajax_referer( 'wpc-ajax-nonce', 'nonce' );
|
62 |
-
$group = absint( $_POST['group'] );
|
63 |
-
|
64 |
-
?><div class='wpc-condition-group wpc-condition-group-<?php echo $group; ?>' data-group='<?php echo $group; ?>'>
|
65 |
-
|
66 |
-
<p class='or-match'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p><?php
|
67 |
-
|
68 |
-
$wp_condition = new WAFS_Condition( null, $group );
|
69 |
-
$wp_condition->output_condition_row();
|
70 |
-
|
71 |
-
?></div>
|
72 |
-
|
73 |
-
<p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
|
74 |
-
|
75 |
-
die();
|
76 |
|
77 |
}
|
78 |
|
@@ -91,7 +39,7 @@ class WAFS_Ajax {
|
|
91 |
$wp_condition = new WAFS_Condition( $_POST['id'], $_POST['group'], $_POST['condition'] );
|
92 |
$value_field_args = $wp_condition->get_value_field_args();
|
93 |
|
94 |
-
?><span class='wpc-value-
|
95 |
wpc_html_field( $value_field_args );
|
96 |
?></span><?php
|
97 |
|
@@ -100,32 +48,4 @@ class WAFS_Ajax {
|
|
100 |
}
|
101 |
|
102 |
|
103 |
-
/**
|
104 |
-
* Update description.
|
105 |
-
*
|
106 |
-
* Render the corresponding description for the condition key.
|
107 |
-
*
|
108 |
-
* @since 1.0.0
|
109 |
-
*/
|
110 |
-
public function update_condition_description() {
|
111 |
-
|
112 |
-
check_ajax_referer( 'wpc-ajax-nonce', 'nonce' );
|
113 |
-
|
114 |
-
$condition = sanitize_text_field( $_POST['condition'] );
|
115 |
-
$wp_condition = new WAFS_Condition( null, null, $condition );
|
116 |
-
|
117 |
-
if ( $desc = $wp_condition->get_description() ) {
|
118 |
-
?><span class='wpc-description wpc-no-description <?php echo $desc; ?>-description'><?php
|
119 |
-
die();
|
120 |
-
}
|
121 |
-
|
122 |
-
?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'>
|
123 |
-
<img class='help_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' data-tip="<?php echo esc_html( $wp_condition->get_description() ); ?>" />
|
124 |
-
</span><?php
|
125 |
-
|
126 |
-
die();
|
127 |
-
|
128 |
-
}
|
129 |
-
|
130 |
-
|
131 |
}
|
19 |
*/
|
20 |
public function __construct() {
|
21 |
|
|
|
|
|
|
|
|
|
22 |
// Update elements
|
23 |
add_action( 'wp_ajax_wafs_update_condition_value', array( $this, 'update_condition_value' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
}
|
26 |
|
39 |
$wp_condition = new WAFS_Condition( $_POST['id'], $_POST['group'], $_POST['condition'] );
|
40 |
$value_field_args = $wp_condition->get_value_field_args();
|
41 |
|
42 |
+
?><span class='wpc-value-field-wrap'><?php
|
43 |
wpc_html_field( $value_field_args );
|
44 |
?></span><?php
|
45 |
|
48 |
}
|
49 |
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
includes/class-wafs-match-conditions.php
CHANGED
@@ -19,339 +19,10 @@ class WAFS_Match_Conditions {
|
|
19 |
* @since 1.0.0
|
20 |
*/
|
21 |
public function __construct() {
|
22 |
-
|
23 |
-
add_filter( 'wafs_match_condition_subtotal', array( $this, 'wafs_match_condition_subtotal' ), 10, 3 );
|
24 |
-
add_filter( 'wafs_match_condition_subtotal_ex_tax', array( $this, 'wafs_match_condition_subtotal_ex_tax' ), 10, 3 );
|
25 |
-
add_filter( 'wafs_match_condition_tax', array( $this, 'wafs_match_condition_tax' ), 10, 3 );
|
26 |
-
add_filter( 'wafs_match_condition_quantity', array( $this, 'wafs_match_condition_quantity' ), 10, 3 );
|
27 |
-
add_filter( 'wafs_match_condition_contains_product', array( $this, 'wafs_match_condition_contains_product' ), 10, 3 );
|
28 |
-
add_filter( 'wafs_match_condition_coupon', array( $this, 'wafs_match_condition_coupon' ), 10, 3 );
|
29 |
-
add_filter( 'wafs_match_condition_weight', array( $this, 'wafs_match_condition_weight' ), 10, 3 );
|
30 |
-
add_filter( 'wafs_match_condition_contains_shipping_class', array( $this, 'wafs_match_condition_contains_shipping_class' ), 10, 3 );
|
31 |
-
|
32 |
add_filter( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 );
|
33 |
-
add_filter( 'wafs_match_condition_city', array( $this, 'wafs_match_condition_city' ), 10, 3 );
|
34 |
-
add_filter( 'wafs_match_condition_state', array( $this, 'wafs_match_condition_state' ), 10, 3 );
|
35 |
-
add_filter( 'wafs_match_condition_country', array( $this, 'wafs_match_condition_country' ), 10, 3 );
|
36 |
-
add_filter( 'wafs_match_condition_role', array( $this, 'wafs_match_condition_role' ), 10, 3 );
|
37 |
-
|
38 |
-
add_filter( 'wafs_match_condition_width', array( $this, 'wafs_match_condition_width' ), 10, 3 );
|
39 |
-
add_filter( 'wafs_match_condition_height', array( $this, 'wafs_match_condition_height' ), 10, 3 );
|
40 |
-
add_filter( 'wafs_match_condition_length', array( $this, 'wafs_match_condition_length' ), 10, 3 );
|
41 |
-
add_filter( 'wafs_match_condition_stock', array( $this, 'wafs_match_condition_stock' ), 10, 3 );
|
42 |
-
add_filter( 'wafs_match_condition_stock_status', array( $this, 'wafs_match_condition_stock_status' ), 10, 3 );
|
43 |
-
add_filter( 'wafs_match_condition_category', array( $this, 'wafs_match_condition_category' ), 10, 3 );
|
44 |
-
|
45 |
-
}
|
46 |
-
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Subtotal.
|
50 |
-
*
|
51 |
-
* Match the condition value against the cart subtotal.
|
52 |
-
*
|
53 |
-
* @since 1.0.0
|
54 |
-
*
|
55 |
-
* @param bool $match Current match value.
|
56 |
-
* @param string $operator Operator selected by the user in the condition row.
|
57 |
-
* @param mixed $value Value given by the user in the condition row.
|
58 |
-
* @return bool Matching result, true if results match, otherwise false.
|
59 |
-
*/
|
60 |
-
public function wafs_match_condition_subtotal( $match, $operator, $value ) {
|
61 |
-
|
62 |
-
if ( ! isset( WC()->cart ) ) return $match;
|
63 |
-
|
64 |
-
if ( '==' == $operator ) :
|
65 |
-
$match = ( WC()->cart->subtotal == $value );
|
66 |
-
elseif ( '!=' == $operator ) :
|
67 |
-
$match = ( WC()->cart->subtotal != $value );
|
68 |
-
elseif ( '>=' == $operator ) :
|
69 |
-
$match = ( WC()->cart->subtotal >= $value );
|
70 |
-
elseif ( '<=' == $operator ) :
|
71 |
-
$match = ( WC()->cart->subtotal <= $value );
|
72 |
-
endif;
|
73 |
-
|
74 |
-
return $match;
|
75 |
-
|
76 |
-
}
|
77 |
-
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Subtotal excl. taxes.
|
81 |
-
*
|
82 |
-
* Match the condition value against the cart subtotal excl. taxes.
|
83 |
-
*
|
84 |
-
* @since 1.0.0
|
85 |
-
*
|
86 |
-
* @param bool $match Current match value.
|
87 |
-
* @param string $operator Operator selected by the user in the condition row.
|
88 |
-
* @param mixed $value Value given by the user in the condition row.
|
89 |
-
* @return bool Matching result, true if results match, otherwise false.
|
90 |
-
*/
|
91 |
-
public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
|
92 |
-
|
93 |
-
if ( ! isset( WC()->cart ) ) return $match;
|
94 |
-
|
95 |
-
if ( '==' == $operator ) :
|
96 |
-
$match = ( WC()->cart->subtotal_ex_tax == $value );
|
97 |
-
elseif ( '!=' == $operator ) :
|
98 |
-
$match = ( WC()->cart->subtotal_ex_tax != $value );
|
99 |
-
elseif ( '>=' == $operator ) :
|
100 |
-
$match = ( WC()->cart->subtotal_ex_tax >= $value );
|
101 |
-
elseif ( '<=' == $operator ) :
|
102 |
-
$match = ( WC()->cart->subtotal_ex_tax <= $value );
|
103 |
-
endif;
|
104 |
-
|
105 |
-
return $match;
|
106 |
-
|
107 |
-
}
|
108 |
-
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Taxes.
|
112 |
-
*
|
113 |
-
* Match the condition value against the cart taxes.
|
114 |
-
*
|
115 |
-
* @since 1.0.0
|
116 |
-
*
|
117 |
-
* @param bool $match Current match value.
|
118 |
-
* @param string $operator Operator selected by the user in the condition row.
|
119 |
-
* @param mixed $value Value given by the user in the condition row.
|
120 |
-
* @return bool Matching result, true if results match, otherwise false.
|
121 |
-
*/
|
122 |
-
public function wafs_match_condition_tax( $match, $operator, $value ) {
|
123 |
-
|
124 |
-
if ( ! isset( WC()->cart ) ) return $match;
|
125 |
-
|
126 |
-
$taxes = array_sum( (array) WC()->cart->taxes );
|
127 |
-
|
128 |
-
if ( '==' == $operator ) :
|
129 |
-
$match = ( $taxes == $value );
|
130 |
-
elseif ( '!=' == $operator ) :
|
131 |
-
$match = ( $taxes != $value );
|
132 |
-
elseif ( '>=' == $operator ) :
|
133 |
-
$match = ( $taxes >= $value );
|
134 |
-
elseif ( '<=' == $operator ) :
|
135 |
-
$match = ( $taxes <= $value );
|
136 |
-
endif;
|
137 |
-
|
138 |
-
return $match;
|
139 |
-
|
140 |
-
}
|
141 |
-
|
142 |
-
|
143 |
-
/**
|
144 |
-
* Quantity.
|
145 |
-
*
|
146 |
-
* Match the condition value against the cart quantity.
|
147 |
-
* This also includes product quantities.
|
148 |
-
*
|
149 |
-
* @since 1.0.0
|
150 |
-
*
|
151 |
-
* @param bool $match Current match value.
|
152 |
-
* @param string $operator Operator selected by the user in the condition row.
|
153 |
-
* @param mixed $value Value given by the user in the condition row.
|
154 |
-
* @return bool Matching result, true if results match, otherwise false.
|
155 |
-
*/
|
156 |
-
public function wafs_match_condition_quantity( $match, $operator, $value ) {
|
157 |
-
|
158 |
-
if ( ! isset( WC()->cart ) ) return $match;
|
159 |
-
|
160 |
-
if ( '==' == $operator ) :
|
161 |
-
$match = ( WC()->cart->cart_contents_count == $value );
|
162 |
-
elseif ( '!=' == $operator ) :
|
163 |
-
$match = ( WC()->cart->cart_contents_count != $value );
|
164 |
-
elseif ( '>=' == $operator ) :
|
165 |
-
$match = ( WC()->cart->cart_contents_count >= $value );
|
166 |
-
elseif ( '<=' == $operator ) :
|
167 |
-
$match = ( WC()->cart->cart_contents_count <= $value );
|
168 |
-
endif;
|
169 |
-
|
170 |
-
return $match;
|
171 |
-
|
172 |
-
}
|
173 |
-
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Contains product.
|
177 |
-
*
|
178 |
-
* Matches if the condition value product is in the cart.
|
179 |
-
*
|
180 |
-
* @since 1.0.0
|
181 |
-
*
|
182 |
-
* @param bool $match Current match value.
|
183 |
-
* @param string $operator Operator selected by the user in the condition row.
|
184 |
-
* @param mixed $value Value given by the user in the condition row.
|
185 |
-
* @return bool Matching result, true if results match, otherwise false.
|
186 |
-
*/
|
187 |
-
public function wafs_match_condition_contains_product( $match, $operator, $value ) {
|
188 |
-
|
189 |
-
if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
|
190 |
-
|
191 |
-
$product_ids = array();
|
192 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
193 |
-
$product_ids[] = $product['product_id'];
|
194 |
-
endforeach;
|
195 |
-
|
196 |
-
if ( '==' == $operator ) :
|
197 |
-
$match = ( in_array( $value, $product_ids ) );
|
198 |
-
elseif ( '!=' == $operator ) :
|
199 |
-
$match = ( ! in_array( $value, $product_ids ) );
|
200 |
-
endif;
|
201 |
-
|
202 |
-
return $match;
|
203 |
-
|
204 |
-
}
|
205 |
-
|
206 |
-
|
207 |
-
/**
|
208 |
-
* Coupon.
|
209 |
-
*
|
210 |
-
* Match the condition value against the applied coupons.
|
211 |
-
*
|
212 |
-
* @since 1.0.0
|
213 |
-
*
|
214 |
-
* @param bool $match Current match value.
|
215 |
-
* @param string $operator Operator selected by the user in the condition row.
|
216 |
-
* @param mixed $value Value given by the user in the condition row.
|
217 |
-
* @return bool Matching result, true if results match, otherwise false.
|
218 |
-
*/
|
219 |
-
public function wafs_match_condition_coupon( $match, $operator, $value ) {
|
220 |
-
|
221 |
-
if ( ! isset( WC()->cart ) ) :
|
222 |
-
return $match;
|
223 |
-
endif;
|
224 |
-
|
225 |
-
$coupons = array( 'percent' => array(), 'fixed' => array() );
|
226 |
-
foreach ( WC()->cart->get_coupons() as $coupon ) {
|
227 |
-
$type = str_replace( '_product', '', $coupon->discount_type );
|
228 |
-
$type = str_replace( '_cart', '', $type );
|
229 |
-
$coupons[ $type ][] = $coupon->coupon_amount;
|
230 |
-
}
|
231 |
-
|
232 |
-
// Match against coupon percentage
|
233 |
-
if ( strpos( $value, '%' ) !== false ) {
|
234 |
-
|
235 |
-
$percentage_value = str_replace( '%', '', $value );
|
236 |
-
if ( '==' == $operator ) :
|
237 |
-
$match = in_array( $percentage_value, $coupons['percent'] );
|
238 |
-
elseif ( '!=' == $operator ) :
|
239 |
-
$match = ! in_array( $percentage_value, $coupons['percent'] );
|
240 |
-
elseif ( '>=' == $operator ) :
|
241 |
-
$match = empty( $coupons['percent'] ) ? $match : ( min( $coupons['percent'] ) >= $percentage_value );
|
242 |
-
elseif ( '<=' == $operator ) :
|
243 |
-
$match = ! is_array( $coupons['percent'] ) ? false : ( max( $coupons['percent'] ) <= $percentage_value );
|
244 |
-
endif;
|
245 |
-
|
246 |
-
// Match against coupon amount
|
247 |
-
} elseif( strpos( $value, '$' ) !== false ) {
|
248 |
-
|
249 |
-
$amount_value = str_replace( '$', '', $value );
|
250 |
-
if ( '==' == $operator ) :
|
251 |
-
$match = in_array( $amount_value, $coupons['fixed'] );
|
252 |
-
elseif ( '!=' == $operator ) :
|
253 |
-
$match = ! in_array( $amount_value, $coupons['fixed'] );
|
254 |
-
elseif ( '>=' == $operator ) :
|
255 |
-
$match = empty( $coupons['fixed'] ) ? $match : ( min( $coupons['fixed'] ) >= $amount_value );
|
256 |
-
elseif ( '<=' == $operator ) :
|
257 |
-
$match = ! is_array( $coupons['fixed'] ) ? $match : ( max( $coupons['fixed'] ) <= $amount_value );
|
258 |
-
endif;
|
259 |
-
|
260 |
-
// Match coupon codes
|
261 |
-
} else {
|
262 |
-
|
263 |
-
if ( '==' == $operator ) :
|
264 |
-
$match = ( in_array( $value, WC()->cart->applied_coupons ) );
|
265 |
-
elseif ( '!=' == $operator ) :
|
266 |
-
$match = ( ! in_array( $value, WC()->cart->applied_coupons ) );
|
267 |
-
endif;
|
268 |
-
|
269 |
-
}
|
270 |
-
|
271 |
-
return $match;
|
272 |
-
|
273 |
-
}
|
274 |
-
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Weight.
|
278 |
-
*
|
279 |
-
* Match the condition value against the cart weight.
|
280 |
-
*
|
281 |
-
* @since 1.0.0
|
282 |
-
*
|
283 |
-
* @param bool $match Current match value.
|
284 |
-
* @param string $operator Operator selected by the user in the condition row.
|
285 |
-
* @param mixed $value Value given by the user in the condition row.
|
286 |
-
* @return bool Matching result, true if results match, otherwise false.
|
287 |
-
*/
|
288 |
-
public function wafs_match_condition_weight( $match, $operator, $value ) {
|
289 |
-
|
290 |
-
if ( ! isset( WC()->cart ) ) return $match;
|
291 |
-
|
292 |
-
if ( '==' == $operator ) :
|
293 |
-
$match = ( WC()->cart->cart_contents_weight == $value );
|
294 |
-
elseif ( '!=' == $operator ) :
|
295 |
-
$match = ( WC()->cart->cart_contents_weight != $value );
|
296 |
-
elseif ( '>=' == $operator ) :
|
297 |
-
$match = ( WC()->cart->cart_contents_weight >= $value );
|
298 |
-
elseif ( '<=' == $operator ) :
|
299 |
-
$match = ( WC()->cart->cart_contents_weight <= $value );
|
300 |
-
endif;
|
301 |
-
|
302 |
-
return $match;
|
303 |
-
|
304 |
}
|
305 |
|
306 |
|
307 |
-
/**
|
308 |
-
* Shipping class.
|
309 |
-
*
|
310 |
-
* Matches if the condition value shipping class is in the cart.
|
311 |
-
*
|
312 |
-
* @since 1.1.0
|
313 |
-
*
|
314 |
-
* @param bool $match Current match value.
|
315 |
-
* @param string $operator Operator selected by the user in the condition row.
|
316 |
-
* @param mixed $value Value given by the user in the condition row.
|
317 |
-
* @return bool Matching result, true if results match, otherwise false.
|
318 |
-
*/
|
319 |
-
public function wafs_match_condition_contains_shipping_class( $match, $operator, $value ) {
|
320 |
-
|
321 |
-
if ( ! isset( WC()->cart ) ) return $match;
|
322 |
-
|
323 |
-
// True until proven false
|
324 |
-
if ( $operator == '!=' ) :
|
325 |
-
$match = true;
|
326 |
-
endif;
|
327 |
-
|
328 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
329 |
-
|
330 |
-
$id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
|
331 |
-
$product = wc_get_product( $id );
|
332 |
-
|
333 |
-
if ( $operator == '==' ) :
|
334 |
-
if ( $product->get_shipping_class() == $value ) :
|
335 |
-
return true;
|
336 |
-
endif;
|
337 |
-
elseif ( $operator == '!=' ) :
|
338 |
-
if ( $product->get_shipping_class() == $value ) :
|
339 |
-
return false;
|
340 |
-
endif;
|
341 |
-
endif;
|
342 |
-
|
343 |
-
endforeach;
|
344 |
-
|
345 |
-
return $match;
|
346 |
-
|
347 |
-
}
|
348 |
-
|
349 |
-
|
350 |
-
/******************************************************
|
351 |
-
* User conditions
|
352 |
-
*****************************************************/
|
353 |
-
|
354 |
-
|
355 |
/**
|
356 |
* Zipcode.
|
357 |
*
|
@@ -450,409 +121,4 @@ class WAFS_Match_Conditions {
|
|
450 |
}
|
451 |
|
452 |
|
453 |
-
/**
|
454 |
-
* City.
|
455 |
-
*
|
456 |
-
* Match the condition value against the users shipping city.
|
457 |
-
*
|
458 |
-
* @since 1.0.0
|
459 |
-
*
|
460 |
-
* @param bool $match Current match value.
|
461 |
-
* @param string $operator Operator selected by the user in the condition row.
|
462 |
-
* @param mixed $value Value given by the user in the condition row.
|
463 |
-
* @return bool Matching result, true if results match, otherwise false.
|
464 |
-
*/
|
465 |
-
public function wafs_match_condition_city( $match, $operator, $value ) {
|
466 |
-
|
467 |
-
if ( ! isset( WC()->customer ) ) return $match;
|
468 |
-
|
469 |
-
$customer_city = strtolower( WC()->customer->get_shipping_city() );
|
470 |
-
$value = strtolower( $value );
|
471 |
-
|
472 |
-
if ( '==' == $operator ) :
|
473 |
-
|
474 |
-
if ( preg_match( '/\, ?/', $value ) ) :
|
475 |
-
$match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
|
476 |
-
else :
|
477 |
-
$match = ( $value == $customer_city );
|
478 |
-
endif;
|
479 |
-
|
480 |
-
elseif ( '!=' == $operator ) :
|
481 |
-
|
482 |
-
if ( preg_match( '/\, ?/', $value ) ) :
|
483 |
-
$match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
|
484 |
-
else :
|
485 |
-
$match = ( $value == $customer_city );
|
486 |
-
endif;
|
487 |
-
|
488 |
-
endif;
|
489 |
-
|
490 |
-
return $match;
|
491 |
-
|
492 |
-
}
|
493 |
-
|
494 |
-
|
495 |
-
/**
|
496 |
-
* State.
|
497 |
-
*
|
498 |
-
* Match the condition value against the users shipping state
|
499 |
-
*
|
500 |
-
* @since 1.0.0
|
501 |
-
*
|
502 |
-
* @param bool $match Current match value.
|
503 |
-
* @param string $operator Operator selected by the user in the condition row.
|
504 |
-
* @param mixed $value Value given by the user in the condition row.
|
505 |
-
* @return bool Matching result, true if results match, otherwise false.
|
506 |
-
*/
|
507 |
-
public function wafs_match_condition_state( $match, $operator, $value ) {
|
508 |
-
|
509 |
-
if ( ! isset( WC()->customer ) ) return $match;
|
510 |
-
|
511 |
-
$state = WC()->customer->get_shipping_country() . '_' . WC()->customer->get_shipping_state();
|
512 |
-
|
513 |
-
if ( '==' == $operator ) :
|
514 |
-
$match = ( $state == $value );
|
515 |
-
elseif ( '!=' == $operator ) :
|
516 |
-
$match = ( $state != $value );
|
517 |
-
endif;
|
518 |
-
|
519 |
-
return $match;
|
520 |
-
|
521 |
-
}
|
522 |
-
|
523 |
-
|
524 |
-
/**
|
525 |
-
* Country.
|
526 |
-
*
|
527 |
-
* Match the condition value against the users shipping country.
|
528 |
-
*
|
529 |
-
* @since 1.0.0
|
530 |
-
*
|
531 |
-
* @param bool $match Current match value.
|
532 |
-
* @param string $operator Operator selected by the user in the condition row.
|
533 |
-
* @param mixed $value Value given by the user in the condition row.
|
534 |
-
* @return bool Matching result, true if results match, otherwise false.
|
535 |
-
*/
|
536 |
-
public function wafs_match_condition_country( $match, $operator, $value ) {
|
537 |
-
|
538 |
-
if ( ! isset( WC()->customer ) ) :
|
539 |
-
return $match;
|
540 |
-
endif;
|
541 |
-
|
542 |
-
$user_country = WC()->customer->get_shipping_country();
|
543 |
-
|
544 |
-
if ( method_exists( WC()->countries, 'get_continent_code_for_country' ) ) :
|
545 |
-
$user_continent = WC()->countries->get_continent_code_for_country( $user_country );
|
546 |
-
endif;
|
547 |
-
|
548 |
-
if ( '==' == $operator ) :
|
549 |
-
$match = stripos( $user_country, $value ) === 0;
|
550 |
-
|
551 |
-
// Check for continents if available
|
552 |
-
if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) :
|
553 |
-
$match = stripos( $user_continent, str_replace( 'CO_','', $value ) ) === 0;
|
554 |
-
endif;
|
555 |
-
elseif ( '!=' == $operator ) :
|
556 |
-
$match = stripos( $user_country, $value ) === false;
|
557 |
-
|
558 |
-
// Check for continents if available
|
559 |
-
if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) :
|
560 |
-
$match = stripos( $user_continent, str_replace( 'CO_','', $value ) ) === false;
|
561 |
-
endif;
|
562 |
-
endif;
|
563 |
-
|
564 |
-
return $match;
|
565 |
-
|
566 |
-
}
|
567 |
-
|
568 |
-
|
569 |
-
/**
|
570 |
-
* User role.
|
571 |
-
*
|
572 |
-
* Match the condition value against the users role.
|
573 |
-
*
|
574 |
-
* @since 1.0.0
|
575 |
-
* @global object $current_user Current user object for capabilities.
|
576 |
-
*
|
577 |
-
* @param bool $match Current match value.
|
578 |
-
* @param string $operator Operator selected by the user in the condition row.
|
579 |
-
* @param mixed $value Value given by the user in the condition row.
|
580 |
-
* @return bool Matching result, true if results match, otherwise false.
|
581 |
-
*/
|
582 |
-
public function wafs_match_condition_role( $match, $operator, $value ) {
|
583 |
-
|
584 |
-
global $current_user;
|
585 |
-
|
586 |
-
if ( '==' == $operator ) :
|
587 |
-
$match = ( array_key_exists( $value, $current_user->caps ) );
|
588 |
-
elseif ( '!=' == $operator ) :
|
589 |
-
$match = ( ! array_key_exists( $value, $current_user->caps ) );
|
590 |
-
endif;
|
591 |
-
|
592 |
-
return $match;
|
593 |
-
|
594 |
-
}
|
595 |
-
|
596 |
-
|
597 |
-
/******************************************************
|
598 |
-
* Product conditions
|
599 |
-
*****************************************************/
|
600 |
-
|
601 |
-
|
602 |
-
/**
|
603 |
-
* Width.
|
604 |
-
*
|
605 |
-
* Match the condition value against the widest product in the cart.
|
606 |
-
*
|
607 |
-
* @since 1.0.0
|
608 |
-
*
|
609 |
-
* @param bool $match Current match value.
|
610 |
-
* @param string $operator Operator selected by the user in the condition row.
|
611 |
-
* @param mixed $value Value given by the user in the condition row.
|
612 |
-
* @return bool Matching result, true if results match, otherwise false.
|
613 |
-
*/
|
614 |
-
public function wafs_match_condition_width( $match, $operator, $value ) {
|
615 |
-
|
616 |
-
if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
|
617 |
-
|
618 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
619 |
-
|
620 |
-
if ( true == $product['data']->variation_has_width ) :
|
621 |
-
$width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) );
|
622 |
-
else :
|
623 |
-
$width[] = ( get_post_meta( $product['product_id'], '_width', true ) );
|
624 |
-
endif;
|
625 |
-
|
626 |
-
endforeach;
|
627 |
-
|
628 |
-
$max_width = max( (array) $width );
|
629 |
-
|
630 |
-
if ( '==' == $operator ) :
|
631 |
-
$match = ( $max_width == $value );
|
632 |
-
elseif ( '!=' == $operator ) :
|
633 |
-
$match = ( $max_width != $value );
|
634 |
-
elseif ( '>=' == $operator ) :
|
635 |
-
$match = ( $max_width >= $value );
|
636 |
-
elseif ( '<=' == $operator ) :
|
637 |
-
$match = ( $max_width <= $value );
|
638 |
-
endif;
|
639 |
-
|
640 |
-
return $match;
|
641 |
-
|
642 |
-
}
|
643 |
-
|
644 |
-
|
645 |
-
/**
|
646 |
-
* Height.
|
647 |
-
*
|
648 |
-
* Match the condition value against the highest product in the cart.
|
649 |
-
*
|
650 |
-
* @since 1.0.0
|
651 |
-
*
|
652 |
-
* @param bool $match Current match value.
|
653 |
-
* @param string $operator Operator selected by the user in the condition row.
|
654 |
-
* @param mixed $value Value given by the user in the condition row.
|
655 |
-
* @return bool Matching result, true if results match, otherwise false.
|
656 |
-
*/
|
657 |
-
public function wafs_match_condition_height( $match, $operator, $value ) {
|
658 |
-
|
659 |
-
if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
|
660 |
-
|
661 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
662 |
-
|
663 |
-
if ( true == $product['data']->variation_has_height ) :
|
664 |
-
$height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) );
|
665 |
-
else :
|
666 |
-
$height[] = ( get_post_meta( $product['product_id'], '_height', true ) );
|
667 |
-
endif;
|
668 |
-
|
669 |
-
endforeach;
|
670 |
-
|
671 |
-
$max_height = max( $height );
|
672 |
-
|
673 |
-
if ( '==' == $operator ) :
|
674 |
-
$match = ( $max_height == $value );
|
675 |
-
elseif ( '!=' == $operator ) :
|
676 |
-
$match = ( $max_height != $value );
|
677 |
-
elseif ( '>=' == $operator ) :
|
678 |
-
$match = ( $max_height >= $value );
|
679 |
-
elseif ( '<=' == $operator ) :
|
680 |
-
$match = ( $max_height <= $value );
|
681 |
-
endif;
|
682 |
-
|
683 |
-
return $match;
|
684 |
-
|
685 |
-
}
|
686 |
-
|
687 |
-
|
688 |
-
/**
|
689 |
-
* Length.
|
690 |
-
*
|
691 |
-
* Match the condition value against the lenghtiest product in the cart.
|
692 |
-
*
|
693 |
-
* @since 1.0.0
|
694 |
-
*
|
695 |
-
* @param bool $match Current match value.
|
696 |
-
* @param string $operator Operator selected by the user in the condition row.
|
697 |
-
* @param mixed $value Value given by the user in the condition row.
|
698 |
-
* @return bool Matching result, true if results match, otherwise false.
|
699 |
-
*/
|
700 |
-
public function wafs_match_condition_length( $match, $operator, $value ) {
|
701 |
-
|
702 |
-
if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
|
703 |
-
|
704 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
705 |
-
|
706 |
-
if ( true == $product['data']->variation_has_length ) :
|
707 |
-
$length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) );
|
708 |
-
else :
|
709 |
-
$length[] = ( get_post_meta( $product['product_id'], '_length', true ) );
|
710 |
-
endif;
|
711 |
-
|
712 |
-
endforeach;
|
713 |
-
|
714 |
-
$max_length = max( $length );
|
715 |
-
|
716 |
-
if ( '==' == $operator ) :
|
717 |
-
$match = ( $max_length == $value );
|
718 |
-
elseif ( '!=' == $operator ) :
|
719 |
-
$match = ( $max_length != $value );
|
720 |
-
elseif ( '>=' == $operator ) :
|
721 |
-
$match = ( $max_length >= $value );
|
722 |
-
elseif ( '<=' == $operator ) :
|
723 |
-
$match = ( $max_length <= $value );
|
724 |
-
endif;
|
725 |
-
|
726 |
-
return $match;
|
727 |
-
|
728 |
-
}
|
729 |
-
|
730 |
-
|
731 |
-
/**
|
732 |
-
* Product stock.
|
733 |
-
*
|
734 |
-
* Match the condition value against all cart products stock.
|
735 |
-
*
|
736 |
-
* @since 1.0.0
|
737 |
-
*
|
738 |
-
* @param bool $match Current match value.
|
739 |
-
* @param string $operator Operator selected by the user in the condition row.
|
740 |
-
* @param mixed $value Value given by the user in the condition row.
|
741 |
-
* @return bool Matching result, true if results match, otherwise false.
|
742 |
-
*/
|
743 |
-
public function wafs_match_condition_stock( $match, $operator, $value ) {
|
744 |
-
|
745 |
-
if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match;
|
746 |
-
|
747 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
748 |
-
|
749 |
-
$product_id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
|
750 |
-
$stock[] = get_post_meta( $product_id, '_stock', true );
|
751 |
-
|
752 |
-
endforeach;
|
753 |
-
|
754 |
-
$min_stock = min( $stock );
|
755 |
-
|
756 |
-
if ( '==' == $operator ) :
|
757 |
-
$match = ( $min_stock == $value );
|
758 |
-
elseif ( '!=' == $operator ) :
|
759 |
-
$match = ( $min_stock != $value );
|
760 |
-
elseif ( '>=' == $operator ) :
|
761 |
-
$match = ( $min_stock >= $value );
|
762 |
-
elseif ( '<=' == $operator ) :
|
763 |
-
$match = ( $min_stock <= $value );
|
764 |
-
endif;
|
765 |
-
|
766 |
-
return $match;
|
767 |
-
|
768 |
-
}
|
769 |
-
|
770 |
-
|
771 |
-
/**
|
772 |
-
* Stock status.
|
773 |
-
*
|
774 |
-
* Match the condition value against all cart products stock statuses.
|
775 |
-
*
|
776 |
-
* @since 1.0.0
|
777 |
-
*
|
778 |
-
* @param bool $match Current match value.
|
779 |
-
* @param string $operator Operator selected by the user in the condition row.
|
780 |
-
* @param mixed $value Value given by the user in the condition row.
|
781 |
-
* @return bool Matching result, true if results match, otherwise false.
|
782 |
-
*/
|
783 |
-
public function wafs_match_condition_stock_status( $match, $operator, $value ) {
|
784 |
-
|
785 |
-
if ( ! isset( WC()->cart ) ) return $match;
|
786 |
-
|
787 |
-
if ( '==' == $operator ) :
|
788 |
-
|
789 |
-
$match = true;
|
790 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
791 |
-
if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value ) {
|
792 |
-
$match = false;
|
793 |
-
}
|
794 |
-
endforeach;
|
795 |
-
|
796 |
-
elseif ( '!=' == $operator ) :
|
797 |
-
|
798 |
-
$match = true;
|
799 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
800 |
-
if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value ) {
|
801 |
-
$match = false;
|
802 |
-
}
|
803 |
-
endforeach;
|
804 |
-
|
805 |
-
endif;
|
806 |
-
|
807 |
-
return $match;
|
808 |
-
|
809 |
-
}
|
810 |
-
|
811 |
-
|
812 |
-
/**
|
813 |
-
* Category.
|
814 |
-
*
|
815 |
-
* Match the condition value against all the cart products category.
|
816 |
-
* With this condition, all the products in the cart must have the given class.
|
817 |
-
*
|
818 |
-
* @since 1.0.0
|
819 |
-
*
|
820 |
-
* @param bool $match Current match value.
|
821 |
-
* @param string $operator Operator selected by the user in the condition row.
|
822 |
-
* @param mixed $value Value given by the user in the condition row.
|
823 |
-
* @return bool Matching result, true if results match, otherwise false.
|
824 |
-
*/
|
825 |
-
public function wafs_match_condition_category( $match, $operator, $value ) {
|
826 |
-
|
827 |
-
if ( ! isset( WC()->cart ) ) return $match;
|
828 |
-
|
829 |
-
$match = true;
|
830 |
-
|
831 |
-
if ( '==' == $operator ) :
|
832 |
-
|
833 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
834 |
-
|
835 |
-
if ( ! has_term( $value, 'product_cat', $product['product_id'] ) ) :
|
836 |
-
$match = false;
|
837 |
-
endif;
|
838 |
-
|
839 |
-
endforeach;
|
840 |
-
|
841 |
-
elseif ( '!=' == $operator ) :
|
842 |
-
|
843 |
-
foreach ( WC()->cart->cart_contents as $product ) :
|
844 |
-
|
845 |
-
if ( has_term( $value, 'product_cat', $product['product_id'] ) ) :
|
846 |
-
$match = false;
|
847 |
-
endif;
|
848 |
-
|
849 |
-
endforeach;
|
850 |
-
|
851 |
-
endif;
|
852 |
-
|
853 |
-
return $match;
|
854 |
-
|
855 |
-
}
|
856 |
-
|
857 |
-
|
858 |
}
|
19 |
* @since 1.0.0
|
20 |
*/
|
21 |
public function __construct() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
add_filter( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
}
|
24 |
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|