Version Description
- Fix - Wrongful url for sub-domain websites
- Add - Added states as condition
Download this release
Release Info
Developer | sormano |
Plugin | WooCommerce Advanced Free Shipping |
Version | 1.0.1 |
Comparing to | |
See all releases |
Version 1.0.1
- assets/css/admin-style.css +118 -0
- assets/js/wafs-js.js +81 -0
- includes/admin/settings/conditions/class-wafs-condition.php +143 -0
- includes/admin/settings/conditions/condition-conditions.php +68 -0
- includes/admin/settings/conditions/condition-descriptions.php +41 -0
- includes/admin/settings/conditions/condition-operators.php +37 -0
- includes/admin/settings/conditions/condition-values.php +201 -0
- includes/admin/settings/meta-box-conditions.php +54 -0
- includes/admin/settings/meta-box-settings.php +31 -0
- includes/admin/views/conditions-table.php +82 -0
- includes/class-wafs-ajax.php +85 -0
- includes/class-wafs-match-conditions.php +664 -0
- includes/class-wafs-method.php +247 -0
- includes/class-wafs-post-type.php +177 -0
- languages/wafs-en_US.mo +0 -0
- languages/wafs-en_US.po +316 -0
- license.txt +621 -0
- readme.txt +50 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- woocommerce-advanced-free-shipping.php +137 -0
assets/css/admin-style.css
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Hide visibility from admin */
|
2 |
+
.post-type-wafs .misc-pub-visibility#visibility {
|
3 |
+
display: none;
|
4 |
+
}
|
5 |
+
|
6 |
+
.wafs-option label {
|
7 |
+
display: inline-block;
|
8 |
+
width: 150px;
|
9 |
+
}
|
10 |
+
|
11 |
+
.wafs_conditions_meta_box > p:first-child + div > .or_match {
|
12 |
+
display: none;
|
13 |
+
}
|
14 |
+
/*
|
15 |
+
* Condition group
|
16 |
+
*/
|
17 |
+
.condition-group {
|
18 |
+
margin-bottom: 30px;
|
19 |
+
background-color: #f5f5f5;
|
20 |
+
padding: 15px 20px 20px;
|
21 |
+
border: 1px solid #ddd;
|
22 |
+
-webkit-box-shadow: 0 1px 1px rgba( 0, 0, 0, .04);
|
23 |
+
box-shadow: 0 1px 1px rgba( 0, 0, 0, .04);
|
24 |
+
}
|
25 |
+
.wafs-condition-wrap {
|
26 |
+
margin: 10px 0px 5px;
|
27 |
+
}
|
28 |
+
.wafs-condition-wrap .wafs-condition {
|
29 |
+
width: 30%;
|
30 |
+
}
|
31 |
+
.wafs-condition-wrap .wafs-operator {
|
32 |
+
width: 12%;
|
33 |
+
min-width: 140px;
|
34 |
+
}
|
35 |
+
.wafs-condition-wrap .wafs-value {
|
36 |
+
width: 30%;
|
37 |
+
}
|
38 |
+
.wafs-condition-wrap input {
|
39 |
+
vertical-align: top;
|
40 |
+
}
|
41 |
+
|
42 |
+
#wafs_conditions p + p {
|
43 |
+
display: none;
|
44 |
+
}
|
45 |
+
/* Description */
|
46 |
+
.wafs_desc {
|
47 |
+
display: none;
|
48 |
+
position: absolute;
|
49 |
+
background: rgba( 0, 0, 0, .8 );
|
50 |
+
min-width: 25px;
|
51 |
+
max-width: 200px;
|
52 |
+
border-radius: 6px;
|
53 |
+
padding: 5px 10px;
|
54 |
+
color: white;
|
55 |
+
margin-top: 10px;
|
56 |
+
right: 40px;
|
57 |
+
text-align: center;
|
58 |
+
}
|
59 |
+
.wafs_desc:after {
|
60 |
+
border-top: 0px solid transparent;
|
61 |
+
border-right: 10px solid transparent;
|
62 |
+
border-left: 10px solid transparent;
|
63 |
+
border-bottom: 10px solid rgba( 0, 0, 0, .8 );
|
64 |
+
content: ' ';
|
65 |
+
position: absolute;
|
66 |
+
top: -10px;
|
67 |
+
right: 10px;
|
68 |
+
z-index: 999;
|
69 |
+
}
|
70 |
+
.wafs_tip:hover ~ .wafs_desc {
|
71 |
+
display: block !important;
|
72 |
+
}
|
73 |
+
.wafs-description {
|
74 |
+
width: 40px;
|
75 |
+
float: right;
|
76 |
+
line-height: 20px;
|
77 |
+
}
|
78 |
+
|
79 |
+
/*
|
80 |
+
* Loading icon
|
81 |
+
*/
|
82 |
+
|
83 |
+
/* Load icon condition row */
|
84 |
+
.wafs-condition-wrap ~ .loading-icon {
|
85 |
+
display: block;
|
86 |
+
}
|
87 |
+
.loading-icon {
|
88 |
+
width: 30%;
|
89 |
+
clear: both;
|
90 |
+
display: inline-block;
|
91 |
+
text-align: center;
|
92 |
+
line-height: 110%;
|
93 |
+
margin: 0 1px;
|
94 |
+
}
|
95 |
+
|
96 |
+
.condition-delete {
|
97 |
+
display: none;
|
98 |
+
opacity: 0;
|
99 |
+
transition: opacity .3s ease-in-out;
|
100 |
+
}
|
101 |
+
.wafs-condition-wrap:hover .condition-delete {
|
102 |
+
display: inline-block;
|
103 |
+
opacity: 1;
|
104 |
+
}
|
105 |
+
|
106 |
+
|
107 |
+
/* � WooCommerce Add icon */
|
108 |
+
.add.button:before {
|
109 |
+
font-family: WooCommerce;
|
110 |
+
speak: none;
|
111 |
+
font-weight: 400;
|
112 |
+
font-variant: normal;
|
113 |
+
text-transform: none;
|
114 |
+
line-height: 1;
|
115 |
+
-webkit-font-smoothing: antialiased;
|
116 |
+
margin-right: 7px;
|
117 |
+
content: "\e007";
|
118 |
+
}
|
assets/js/wafs-js.js
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery( function( $ ) {
|
2 |
+
|
3 |
+
var loading_icon = '<span class="loading-icon"><img src="/wp-admin/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' ) };
|
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 |
+
};
|
41 |
+
|
42 |
+
// Insert condition group
|
43 |
+
$.post( ajaxurl, data, function( response ) {
|
44 |
+
$( '.condition-group ~ .loading-icon' ).last().remove();
|
45 |
+
$( '.wafs_conditions' ).append( response ).children( ':last' ).hide().fadeIn( 'normal' );
|
46 |
+
});
|
47 |
+
|
48 |
+
});
|
49 |
+
|
50 |
+
// Update condition values
|
51 |
+
$( '#wafs_conditions' ).on( 'change', '.wafs-condition', function () {
|
52 |
+
|
53 |
+
var data = {
|
54 |
+
action: 'wafs_update_condition_value',
|
55 |
+
id: $( this ).attr( 'data-id' ),
|
56 |
+
group: $( this ).attr( 'data-group' ),
|
57 |
+
condition: $( this ).val()
|
58 |
+
};
|
59 |
+
|
60 |
+
var replace = '.wafs-value-wrap-' + data.id;
|
61 |
+
|
62 |
+
$( replace ).html( loading_icon );
|
63 |
+
|
64 |
+
$.post( ajaxurl, data, function( response ) {
|
65 |
+
$( replace ).replaceWith( response );
|
66 |
+
});
|
67 |
+
|
68 |
+
// Update condition description
|
69 |
+
var description = {
|
70 |
+
action: 'wafs_update_condition_description',
|
71 |
+
condition: data.condition
|
72 |
+
};
|
73 |
+
|
74 |
+
$.post( ajaxurl, description, function( description_response ) {
|
75 |
+
$( replace + ' ~ .wafs-description' ).replaceWith( description_response );
|
76 |
+
})
|
77 |
+
|
78 |
+
|
79 |
+
});
|
80 |
+
|
81 |
+
});
|
includes/admin/settings/conditions/class-wafs-condition.php
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
class Wafs_Condition {
|
14 |
+
|
15 |
+
public $condition;
|
16 |
+
public $operator;
|
17 |
+
public $value;
|
18 |
+
public $group;
|
19 |
+
public $id;
|
20 |
+
|
21 |
+
|
22 |
+
/**
|
23 |
+
* __construct functon.
|
24 |
+
*/
|
25 |
+
public function __construct( $id = null, $group = 0, $condition = null, $operator = null, $value = null ) {
|
26 |
+
|
27 |
+
$this->id = $id;
|
28 |
+
$this->group = $group;
|
29 |
+
$this->condition = $condition;
|
30 |
+
$this->operator = $operator;
|
31 |
+
$this->value = $value;
|
32 |
+
|
33 |
+
if ( ! $id )
|
34 |
+
$this->id = rand();
|
35 |
+
|
36 |
+
$this->wafs_create_object();
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Create condition.
|
43 |
+
*
|
44 |
+
* Created a condition rule object
|
45 |
+
*/
|
46 |
+
public function wafs_create_object() {
|
47 |
+
|
48 |
+
?><div class='wafs-condition-wrap'><?php
|
49 |
+
|
50 |
+
do_action( 'wafs_before_condition' );
|
51 |
+
|
52 |
+
$this->wafs_condition_conditions();
|
53 |
+
$this->wafs_condition_operator();
|
54 |
+
$this->wafs_condition_values();
|
55 |
+
|
56 |
+
$this->wafs_add_condition_button();
|
57 |
+
$this->wafs_remove_condition_button();
|
58 |
+
|
59 |
+
$this->wafs_condition_description();
|
60 |
+
|
61 |
+
do_action( 'wafs_after_condition' );
|
62 |
+
|
63 |
+
?></div><?php
|
64 |
+
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Condition dropdown.
|
70 |
+
*
|
71 |
+
* Render and load condition dropdown
|
72 |
+
*/
|
73 |
+
public function wafs_condition_conditions() {
|
74 |
+
|
75 |
+
wafs_condition_conditions( $this->id, $this->group, $this->condition );
|
76 |
+
|
77 |
+
}
|
78 |
+
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Operator dropdown.
|
82 |
+
*
|
83 |
+
* Render and load operator dropdown
|
84 |
+
*/
|
85 |
+
public function wafs_condition_operator() {
|
86 |
+
|
87 |
+
wafs_condition_operator( $this->id, $this->group, $this->operator );
|
88 |
+
|
89 |
+
}
|
90 |
+
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Value dropdown.
|
94 |
+
*
|
95 |
+
* Render and load value dropdown
|
96 |
+
*/
|
97 |
+
public function wafs_condition_values() {
|
98 |
+
|
99 |
+
wafs_condition_values( $this->id, $this->group, $this->condition, $this->value );
|
100 |
+
|
101 |
+
}
|
102 |
+
|
103 |
+
public function wafs_add_condition_button() {
|
104 |
+
?>
|
105 |
+
<a class='button condition-add' data-group='<?php echo $this->group; ?>' href='javascript:void(0);'>+</a>
|
106 |
+
<?php
|
107 |
+
}
|
108 |
+
|
109 |
+
public function wafs_remove_condition_button() {
|
110 |
+
?>
|
111 |
+
<a class='button condition-delete' href='javascript:void(0);'>-</a>
|
112 |
+
<?php
|
113 |
+
}
|
114 |
+
|
115 |
+
public function wafs_condition_description() {
|
116 |
+
|
117 |
+
wafs_condition_description( $this->condition );
|
118 |
+
|
119 |
+
}
|
120 |
+
|
121 |
+
}
|
122 |
+
/**
|
123 |
+
* Load condition keys dropdown.
|
124 |
+
*/
|
125 |
+
require_once plugin_dir_path( __FILE__ ) . 'condition-conditions.php';
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Load condition operator dropdown.
|
129 |
+
*/
|
130 |
+
require_once plugin_dir_path( __FILE__ ) . 'condition-operators.php';
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Load condition value dropdown.
|
134 |
+
*/
|
135 |
+
require_once plugin_dir_path( __FILE__ ) . 'condition-values.php';
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Load condition descriptions.
|
139 |
+
*/
|
140 |
+
require_once plugin_dir_path( __FILE__ ) . 'condition-descriptions.php';
|
141 |
+
|
142 |
+
|
143 |
+
?>
|
includes/admin/settings/conditions/condition-conditions.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function wafs_condition_conditions( $id, $group = 0, $current_value = 'total' ) {
|
4 |
+
|
5 |
+
$conditions = array(
|
6 |
+
__( 'Cart', 'wafs' ) => array(
|
7 |
+
'subtotal' => __( 'Subtotal', 'wafs' ),
|
8 |
+
'subtotal_ex_tax' => __( 'Subtotal ex. taxes', 'wafs' ),
|
9 |
+
'tax' => __( 'Tax', 'wafs' ),
|
10 |
+
'quantity' => __( 'Quantity', 'wafs' ),
|
11 |
+
'contains_product' => __( 'Contains product', 'wafs' ),
|
12 |
+
'coupon' => __( 'Coupon', 'wafs' ),
|
13 |
+
),
|
14 |
+
__( 'User Details', 'wafs' ) => array(
|
15 |
+
'zipcode' => __( 'Zipcode', 'wafs' ),
|
16 |
+
'city' => __( 'City', 'wafs' ),
|
17 |
+
'state' => __( 'State', 'wafs' ),
|
18 |
+
'country' => __( 'Country', 'wafs' ),
|
19 |
+
'role' => __( 'User role', 'wafs' ),
|
20 |
+
),
|
21 |
+
__( 'Product', 'wafs' ) => array(
|
22 |
+
'width' => __( 'Width', 'wafs' ),
|
23 |
+
'height' => __( 'Height', 'wafs' ),
|
24 |
+
'length' => __( 'Length', 'wafs' ),
|
25 |
+
'weight' => __( 'Weight', 'wafs' ),
|
26 |
+
'stock' => __( 'Stock', 'wafs' ),
|
27 |
+
'stock_status' => __( 'Stock status', 'wafs' ),
|
28 |
+
'backorder' => __( 'Backorders', 'wafs' ),
|
29 |
+
'category' => __( 'Category', 'wafs' ),
|
30 |
+
),
|
31 |
+
);
|
32 |
+
|
33 |
+
$conditions = apply_filters( 'wafs_conditions', $conditions );
|
34 |
+
|
35 |
+
?>
|
36 |
+
|
37 |
+
<span class='wafs-condition-wrap wafs-condition-wrap-<?php echo $id; ?>'>
|
38 |
+
|
39 |
+
<select class='wafs-condition' data-group='<?php echo $group; ?>' data-id='<?php echo $id; ?>'
|
40 |
+
name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][condition]'>
|
41 |
+
|
42 |
+
<?php echo $selected;
|
43 |
+
foreach ( $conditions as $option_group => $values ) :
|
44 |
+
|
45 |
+
?><optgroup label='<?php echo $option_group; ?>'><?php
|
46 |
+
|
47 |
+
foreach ( $values as $key => $value ) :
|
48 |
+
|
49 |
+
$selected = ( $key == $current_value ) ? "SELECTED" : null;
|
50 |
+
|
51 |
+
?><option value='<?php echo $key; ?>' <?php echo $selected; ?>><?php echo $value; ?></option><?php
|
52 |
+
|
53 |
+
endforeach;
|
54 |
+
|
55 |
+
?></optgroup><?php
|
56 |
+
|
57 |
+
endforeach;
|
58 |
+
?>
|
59 |
+
|
60 |
+
</select>
|
61 |
+
|
62 |
+
</span>
|
63 |
+
|
64 |
+
<?php
|
65 |
+
|
66 |
+
}
|
67 |
+
|
68 |
+
?>
|
includes/admin/settings/conditions/condition-descriptions.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function wafs_condition_description( $condition ) {
|
4 |
+
|
5 |
+
global $woocommerce;
|
6 |
+
|
7 |
+
$descriptions = array(
|
8 |
+
'state' => __( 'States are only available in the U.S.', 'wafs' ),
|
9 |
+
'weight' => __( 'Weight calculated on all the cart contents', 'wafs' ),
|
10 |
+
'length' => __( 'Compared to lengthiest product in cart', 'wafs' ),
|
11 |
+
'width' => __( 'Compared to widest product in cart', 'wafs' ),
|
12 |
+
'height' => __( 'Compared to highest product in cart', 'wafs' ),
|
13 |
+
'stock_status' => __( 'All products in cart must match stock status', 'wafs' ),
|
14 |
+
'backorder' => __( 'All products in cart must match backorder', 'wafs' ),
|
15 |
+
'category' => __( 'All products in cart must match category', 'wafs' ),
|
16 |
+
'contains_product' => __( 'Cart must contain one of this product', 'wafs' ),
|
17 |
+
);
|
18 |
+
|
19 |
+
// Display description
|
20 |
+
?>
|
21 |
+
<span class='wafs-description <?php echo $descriptions[ $condition ]; ?>-description'>
|
22 |
+
|
23 |
+
<div class='description'>
|
24 |
+
|
25 |
+
<?php if ( isset( $descriptions[ $condition ] ) ) : ?>
|
26 |
+
|
27 |
+
<img class='wafs_tip' src='<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png' height='24' width='24' />
|
28 |
+
|
29 |
+
<div class='wafs_desc'>
|
30 |
+
<?php echo $descriptions[ $condition ]; ?>
|
31 |
+
</div>
|
32 |
+
|
33 |
+
<?php endif; ?>
|
34 |
+
|
35 |
+
</div>
|
36 |
+
|
37 |
+
</span>
|
38 |
+
<?php
|
39 |
+
|
40 |
+
}
|
41 |
+
?>
|
includes/admin/settings/conditions/condition-operators.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function wafs_condition_operator( $id, $group = 0, $current_value = '==' ) {
|
4 |
+
|
5 |
+
$operators = array(
|
6 |
+
'==' => __( 'Equal to', 'wafs' ),
|
7 |
+
'!=' => __( 'Not equal to', 'wafs' ),
|
8 |
+
'>=' => __( 'Greater or equal to', 'wafs' ),
|
9 |
+
'<=' => __( 'Less or equal to ', 'wafs' ),
|
10 |
+
);
|
11 |
+
|
12 |
+
$operators = apply_filters( 'wafs_operators', $operators );
|
13 |
+
|
14 |
+
?>
|
15 |
+
|
16 |
+
<span class='wafs-operator-wrap wafs-operator-wrap-<?php echo $id; ?>'>
|
17 |
+
|
18 |
+
<select id='' class='wafs-operator' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][operator]'>
|
19 |
+
|
20 |
+
<?php
|
21 |
+
foreach ( $operators as $key => $value ) :
|
22 |
+
$selected = ( $key == $current_value ) ? "SELECTED" : null;
|
23 |
+
?>
|
24 |
+
<option value='<?php echo $key; ?>' <?php echo $selected; ?>><?php echo $value; ?></option>
|
25 |
+
<?php
|
26 |
+
endforeach;
|
27 |
+
?>
|
28 |
+
|
29 |
+
</select>
|
30 |
+
|
31 |
+
</span>
|
32 |
+
|
33 |
+
<?php
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
?>
|
includes/admin/settings/conditions/condition-values.php
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $current_value = '' ) {
|
4 |
+
|
5 |
+
global $woocommerce;
|
6 |
+
|
7 |
+
switch ( $condition ) :
|
8 |
+
|
9 |
+
default:
|
10 |
+
case 'subtotal' :
|
11 |
+
|
12 |
+
$values['field'] = 'number';
|
13 |
+
|
14 |
+
break;
|
15 |
+
|
16 |
+
case 'subtotal_ex_tax' :
|
17 |
+
|
18 |
+
$values['field'] = 'number';
|
19 |
+
|
20 |
+
break;
|
21 |
+
|
22 |
+
case 'tax' :
|
23 |
+
|
24 |
+
$values['field'] = 'number';
|
25 |
+
|
26 |
+
break;
|
27 |
+
|
28 |
+
case 'quantity' :
|
29 |
+
|
30 |
+
$values['field'] = 'number';
|
31 |
+
|
32 |
+
break;
|
33 |
+
|
34 |
+
case 'contains_product' :
|
35 |
+
|
36 |
+
$values['field'] = 'select';
|
37 |
+
|
38 |
+
$products = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'product', 'order' => 'asc', 'orderby' => 'title' ) );
|
39 |
+
foreach ( $products as $product ) :
|
40 |
+
$values['values'][$product->ID ] = $product->post_title;
|
41 |
+
endforeach;
|
42 |
+
|
43 |
+
break;
|
44 |
+
|
45 |
+
case 'coupon' :
|
46 |
+
|
47 |
+
$values['field'] = 'text';
|
48 |
+
|
49 |
+
break;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* User details
|
53 |
+
*/
|
54 |
+
|
55 |
+
case 'zipcode' :
|
56 |
+
|
57 |
+
$values['field'] = 'text';
|
58 |
+
|
59 |
+
break;
|
60 |
+
|
61 |
+
case 'city' :
|
62 |
+
|
63 |
+
$values['field'] = 'text';
|
64 |
+
|
65 |
+
break;
|
66 |
+
|
67 |
+
case 'state' :
|
68 |
+
|
69 |
+
$values['field'] = 'select';
|
70 |
+
$values['values'] = $woocommerce->countries->get_states( 'US' );
|
71 |
+
|
72 |
+
break;
|
73 |
+
|
74 |
+
case 'country' :
|
75 |
+
|
76 |
+
$values['field'] = 'select';
|
77 |
+
$values['values'] = $woocommerce->countries->get_allowed_countries();
|
78 |
+
|
79 |
+
break;
|
80 |
+
|
81 |
+
case 'role' :
|
82 |
+
|
83 |
+
$values['field'] = 'select';
|
84 |
+
$roles = array_keys( get_editable_roles() );
|
85 |
+
$values['values'] = array_combine( $roles, $roles );
|
86 |
+
|
87 |
+
break;
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Product
|
91 |
+
*/
|
92 |
+
|
93 |
+
case 'width' :
|
94 |
+
|
95 |
+
$values['field'] = 'text';
|
96 |
+
|
97 |
+
break;
|
98 |
+
|
99 |
+
|
100 |
+
case 'height' :
|
101 |
+
|
102 |
+
$values['field'] = 'text';
|
103 |
+
|
104 |
+
break;
|
105 |
+
|
106 |
+
|
107 |
+
case 'length' :
|
108 |
+
|
109 |
+
$values['field'] = 'text';
|
110 |
+
|
111 |
+
break;
|
112 |
+
|
113 |
+
case 'weight' :
|
114 |
+
|
115 |
+
$values['field'] = 'text';
|
116 |
+
|
117 |
+
break;
|
118 |
+
|
119 |
+
case 'stock' :
|
120 |
+
|
121 |
+
$values['field'] = 'text';
|
122 |
+
|
123 |
+
break;
|
124 |
+
|
125 |
+
case 'stock_status' :
|
126 |
+
|
127 |
+
$values['field'] = 'select';
|
128 |
+
$values['values'] = array(
|
129 |
+
'instock' => __( 'In stock', 'wafs' ),
|
130 |
+
'outofstock' => __( 'Out of stock', 'wafs' ),
|
131 |
+
);
|
132 |
+
|
133 |
+
break;
|
134 |
+
|
135 |
+
case 'backorder' :
|
136 |
+
|
137 |
+
$values['backorder'] = 'select';
|
138 |
+
$values['values'] = array(
|
139 |
+
'no' => __( 'Do not allow', 'woocommerce' ),
|
140 |
+
'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
|
141 |
+
'yes' => __( 'Allow', 'woocommerce' )
|
142 |
+
);
|
143 |
+
|
144 |
+
break;
|
145 |
+
|
146 |
+
case 'category' :
|
147 |
+
|
148 |
+
$values['field'] = 'select';
|
149 |
+
|
150 |
+
$categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
|
151 |
+
foreach ( $categories as $category ) :
|
152 |
+
$values['values'][ $category->slug ] = $category->name;
|
153 |
+
endforeach;
|
154 |
+
|
155 |
+
break;
|
156 |
+
|
157 |
+
|
158 |
+
endswitch;
|
159 |
+
?>
|
160 |
+
|
161 |
+
<span class='wafs-value-wrap wafs-value-wrap-<?php echo $id; ?>'>
|
162 |
+
|
163 |
+
<?php
|
164 |
+
switch ( $values['field'] ) :
|
165 |
+
|
166 |
+
case 'text' :
|
167 |
+
?>
|
168 |
+
<input type='text' class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'
|
169 |
+
placeholder='<?php echo $values['placeholder']; ?>' value='<?php echo $current_value; ?>'>
|
170 |
+
<?php
|
171 |
+
break;
|
172 |
+
|
173 |
+
case 'number' :
|
174 |
+
?>
|
175 |
+
<input type='text' class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'
|
176 |
+
min='<?php echo $values['min']; ?>' max='<?php echo $values['max']; ?>' placeholder='<?php echo $values['placeholder']; ?>'
|
177 |
+
value='<?php echo $current_value; ?>'>
|
178 |
+
<?php
|
179 |
+
break;
|
180 |
+
|
181 |
+
default :
|
182 |
+
case 'select' :
|
183 |
+
?><select class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'><?php
|
184 |
+
foreach ( $values['values'] as $key => $value ) :
|
185 |
+
$selected = ( $key == $current_value ) ? 'SELECTED' : null;
|
186 |
+
?><option value='<?php echo $key; ?>' <?php echo $selected; ?>><?php echo $value; ?></option><?php
|
187 |
+
endforeach;
|
188 |
+
?></select><?php
|
189 |
+
break;
|
190 |
+
|
191 |
+
endswitch;
|
192 |
+
|
193 |
+
?>
|
194 |
+
|
195 |
+
</span>
|
196 |
+
|
197 |
+
<?php
|
198 |
+
|
199 |
+
}
|
200 |
+
|
201 |
+
?>
|
includes/admin/settings/meta-box-conditions.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
wp_nonce_field( 'wafs_conditions_meta_box', 'wafs_conditions_meta_box_nonce' );
|
13 |
+
|
14 |
+
global $post;
|
15 |
+
$conditions = get_post_meta( $post->ID, '_wafs_shipping_method_conditions', true );
|
16 |
+
|
17 |
+
?>
|
18 |
+
<div class='wafs wafs_conditions wafs_meta_box wafs_conditions_meta_box'>
|
19 |
+
|
20 |
+
<p><strong><?php _e( 'Match all of the following rules to allow free shipping:', 'wafs' ); ?></strong></p>
|
21 |
+
|
22 |
+
<?php
|
23 |
+
if ( !empty( $conditions ) ) :
|
24 |
+
|
25 |
+
foreach ( $conditions as $condition_group => $conditions ) :
|
26 |
+
?>
|
27 |
+
<div class='condition-group condition-group-<?php echo $condition_group; ?>' data-group='<?php echo $condition_group; ?>'>
|
28 |
+
|
29 |
+
<p class='or_match'><?php _e( 'Or match all of the following rules to allow free shipping:', 'wafs' );?></p>
|
30 |
+
<?php
|
31 |
+
foreach ( $conditions as $condition_id => $condition ) :
|
32 |
+
|
33 |
+
new Wafs_Condition( $condition_id, $condition_group, $condition['condition'], $condition['operator'], $condition['value'] );
|
34 |
+
|
35 |
+
endforeach;
|
36 |
+
?>
|
37 |
+
</div>
|
38 |
+
|
39 |
+
<p><strong><?php _e( 'Or', 'wafs' ); ?></strong></p>
|
40 |
+
<?php
|
41 |
+
endforeach;
|
42 |
+
|
43 |
+
else :
|
44 |
+
|
45 |
+
?><div class='condition-group condition-group-0' data-group='0'><?php
|
46 |
+
new Wafs_Condition();
|
47 |
+
?></div><?php
|
48 |
+
|
49 |
+
endif;
|
50 |
+
?>
|
51 |
+
|
52 |
+
</div>
|
53 |
+
|
54 |
+
<a class='button condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'wafs' ); ?></a>
|
includes/admin/settings/meta-box-settings.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WAFS meta box settings
|
4 |
+
*
|
5 |
+
* Display the shipping settings in the meta box
|
6 |
+
*
|
7 |
+
* @author Jeroen Sormani
|
8 |
+
* @package WooCommerce Advanced Free Shipping
|
9 |
+
* @version 1.0.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
wp_nonce_field( 'wafs_settings_meta_box', 'wafs_settings_meta_box_nonce' );
|
13 |
+
|
14 |
+
global $post;
|
15 |
+
$settings = get_post_meta( $post->ID, '_wafs_shipping_method' );
|
16 |
+
?>
|
17 |
+
<div class='wafs wafs_settings wafs_meta_box wafs_settings_meta_box'>
|
18 |
+
|
19 |
+
<p class='wafs-option'>
|
20 |
+
|
21 |
+
<label for='shipping_title'><?php _e( 'Shipping title', 'wafs' ); ?></label>
|
22 |
+
<input type='text' class='' id='shipping_title' name='_wafs_shipping_method[shipping_title]'
|
23 |
+
value='<?php echo $settings[0]['shipping_title']; ?>' placeholder='<?php _e( 'e.g. Free Shipping', 'wafs' ); ?>'>
|
24 |
+
|
25 |
+
</p>
|
26 |
+
|
27 |
+
|
28 |
+
</div>
|
29 |
+
<?php
|
30 |
+
|
31 |
+
?>
|
includes/admin/views/conditions-table.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Conditions table
|
4 |
+
*
|
5 |
+
* Display table with all the user configured Free shipping conditions
|
6 |
+
*
|
7 |
+
* @author Jeroen Sormani
|
8 |
+
* @package WooCommerce Advanced Free Shipping
|
9 |
+
* @version 1.0.0
|
10 |
+
*/
|
11 |
+
$method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'wafs' ) );
|
12 |
+
?>
|
13 |
+
<tr valign="top">
|
14 |
+
<th scope="row" class="titledesc">
|
15 |
+
<?php _e( 'Method conditions', 'wafs' ); ?>:<br />
|
16 |
+
<small>Read more</small>
|
17 |
+
</th>
|
18 |
+
<td class="forminp" id="<?php echo $this->id; ?>_flat_rates">
|
19 |
+
|
20 |
+
<table class='wp-list-table wafs-table widefat'>
|
21 |
+
<thead>
|
22 |
+
<tr>
|
23 |
+
<th style='padding-left: 10px;'><?php _e( 'Title', 'wafs' ); ?></th>
|
24 |
+
<th><?php _e( 'Shipping title', 'wafs' ); ?></th>
|
25 |
+
<th><?php _e( 'Condition groups', 'wafs' ); ?></th>
|
26 |
+
<th><?php _e( 'Author', 'wafs' ); ?></th>
|
27 |
+
</tr>
|
28 |
+
</thead>
|
29 |
+
<tbody>
|
30 |
+
<?php
|
31 |
+
foreach ( $method_conditions as $method_condition ) :
|
32 |
+
$method_details = get_post_meta( $method_condition->ID, '_wafs_shipping_method', true );
|
33 |
+
$conditions = get_post_meta( $method_condition->ID, '_wafs_shipping_method_conditions', true );
|
34 |
+
?>
|
35 |
+
<tr>
|
36 |
+
<td>
|
37 |
+
<strong>
|
38 |
+
<a href='<?php echo get_edit_post_link( $method_condition->ID ); ?>' class='row-title' title='<?php _e( 'Edit Method', 'wafs' ); ?>'>
|
39 |
+
<?php echo $method_condition->post_title; echo empty( $method_condition->post_title) ? __( 'Untitled', 'wafs' ) : null; ?>
|
40 |
+
</a>
|
41 |
+
</strong>
|
42 |
+
<div class='row-actions'>
|
43 |
+
<span class='edit'>
|
44 |
+
<a href='<?php echo get_edit_post_link( $method_condition->ID ); ?>' title='<?php _e( 'Edit Method', 'wafs' ); ?>'>
|
45 |
+
<?php _e( 'Edit', 'wafs' ); ?>
|
46 |
+
</a>
|
47 |
+
|
|
48 |
+
</span>
|
49 |
+
<span class='trash'>
|
50 |
+
<a href='<?php echo get_delete_post_link( $method_condition->ID ); ?>' title='<?php _e( 'Delete Method', 'wafs' ); ?>'>
|
51 |
+
<?php _e( 'Delete', 'wafs' ); ?>
|
52 |
+
</a>
|
53 |
+
</span>
|
54 |
+
</div>
|
55 |
+
</td>
|
56 |
+
<td><?php echo empty( $method_details['shipping_title'] ) ? __( 'Free Shipping', 'wafs') : $method_details['shipping_title']; ?></td>
|
57 |
+
<td><?php echo count( $conditions ); ?></td>
|
58 |
+
<td><?php echo get_the_author_meta( 'display_name', $method_condition->post_author ); ?></a>
|
59 |
+
</td>
|
60 |
+
</tr>
|
61 |
+
<?php
|
62 |
+
endforeach;
|
63 |
+
|
64 |
+
if ( empty( $method_conditions ) ) :
|
65 |
+
?>
|
66 |
+
<tr>
|
67 |
+
<td colspan='2'><?php _e( 'There are no Free Shipping conditions. Yet...', 'wafs' ); ?></td>
|
68 |
+
</tr>
|
69 |
+
<?php
|
70 |
+
endif;
|
71 |
+
?>
|
72 |
+
</tbody>
|
73 |
+
<tfoot>
|
74 |
+
<tr>
|
75 |
+
<th colspan='4' style='padding-left: 10px;'>
|
76 |
+
<a href='<?php echo admin_url( 'post-new.php?post_type=wafs' ); ?>' class='add button'><?php _e( 'Add Free Shipping Method', 'wapl' ); ?></a>
|
77 |
+
</th>
|
78 |
+
</tr>
|
79 |
+
</tfoot>
|
80 |
+
</table>
|
81 |
+
</td>
|
82 |
+
</tr>
|
includes/class-wafs-ajax.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Wafs_post_type
|
4 |
+
*
|
5 |
+
* Initialize the WAFS post type
|
6 |
+
*
|
7 |
+
* @class Wafs_post_type
|
8 |
+
* @author Jeroen Sormani
|
9 |
+
* @package WooCommerce Advanced Free Shipping
|
10 |
+
* @version 1.0.0
|
11 |
+
*/
|
12 |
+
class Wafs_Ajax {
|
13 |
+
|
14 |
+
|
15 |
+
/* Construct.
|
16 |
+
*
|
17 |
+
* Add ajax actions in order to work.
|
18 |
+
*/
|
19 |
+
public function __construct() {
|
20 |
+
|
21 |
+
// Add elements
|
22 |
+
add_action( 'wp_ajax_wafs_add_condition', array( $this, 'wafs_add_condition' ) );
|
23 |
+
add_action( 'wp_ajax_wafs_add_condition_group', array( $this, 'wafs_add_condition_group' ) );
|
24 |
+
|
25 |
+
// Update elements
|
26 |
+
add_action( 'wp_ajax_wafs_update_condition_value', array( $this, 'wafs_update_condition_value' ) );
|
27 |
+
add_action( 'wp_ajax_wafs_update_condition_description', array( $this, 'wafs_update_condition_description' ) );
|
28 |
+
|
29 |
+
}
|
30 |
+
|
31 |
+
/*
|
32 |
+
* Render new condition
|
33 |
+
*/
|
34 |
+
public function wafs_add_condition() {
|
35 |
+
|
36 |
+
new Wafs_Condition( null, $_POST['group'] );
|
37 |
+
die();
|
38 |
+
|
39 |
+
}
|
40 |
+
|
41 |
+
/*
|
42 |
+
* Render new condition group.
|
43 |
+
*/
|
44 |
+
public function wafs_add_condition_group() {
|
45 |
+
?>
|
46 |
+
<div class='condition-group condition-group-<?php echo $_POST['group']; ?>' data-group='<?php echo $_POST['group']; ?>'>
|
47 |
+
|
48 |
+
<p class='or_match'><?php _e( 'Or match all of the following rules to allow free shipping:', 'wafs' );?></p>
|
49 |
+
<?php
|
50 |
+
new Wafs_Condition( null, $_POST['group'] );
|
51 |
+
?>
|
52 |
+
|
53 |
+
</div>
|
54 |
+
|
55 |
+
<p><strong><?php _e( 'Or', 'wafs' ); ?></strong></p>
|
56 |
+
|
57 |
+
<?php
|
58 |
+
die();
|
59 |
+
}
|
60 |
+
|
61 |
+
/* Update condition values.
|
62 |
+
*
|
63 |
+
* Retreive and render the new condition values according to the condition key
|
64 |
+
*/
|
65 |
+
public function wafs_update_condition_value() {
|
66 |
+
|
67 |
+
wafs_condition_values( $_POST['id'], $_POST['group'], $_POST['condition'] );
|
68 |
+
die();
|
69 |
+
|
70 |
+
}
|
71 |
+
|
72 |
+
/* Update condition description
|
73 |
+
*
|
74 |
+
* Render the corresponding description for the condition key
|
75 |
+
*/
|
76 |
+
public function wafs_update_condition_description() {
|
77 |
+
|
78 |
+
wafs_condition_description( $_POST['condition'] );
|
79 |
+
die();
|
80 |
+
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
}
|
85 |
+
new Wafs_Ajax();
|
includes/class-wafs-match-conditions.php
ADDED
@@ -0,0 +1,664 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Wafs_Match_Conditions
|
4 |
+
*
|
5 |
+
* The WAFS Match Conditions class handles the matching rules for Free Shipping
|
6 |
+
*
|
7 |
+
* @class Wapl_Conditions
|
8 |
+
* @author Jeroen Sormani
|
9 |
+
* @package WooCommerce Advanced Product Labels
|
10 |
+
* @version 1.0.0
|
11 |
+
*/
|
12 |
+
class Wafs_Match_Conditions {
|
13 |
+
|
14 |
+
|
15 |
+
/**
|
16 |
+
* __construct functon.
|
17 |
+
*/
|
18 |
+
public function __construct() {
|
19 |
+
|
20 |
+
global $woocommerce;
|
21 |
+
|
22 |
+
add_action( 'wafs_match_condition_subtotal', array( $this, 'wafs_match_condition_subtotal' ), 10, 3 );
|
23 |
+
add_action( 'wafs_match_condition_subtotal_ex_tax', array( $this, 'wafs_match_condition_subtotal_ex_tax' ), 10, 3 );
|
24 |
+
add_action( 'wafs_match_condition_tax', array( $this, 'wafs_match_condition_tax' ), 10, 3 );
|
25 |
+
add_action( 'wafs_match_condition_quantity', array( $this, 'wafs_match_condition_quantity' ), 10, 3 );
|
26 |
+
add_action( 'wafs_match_condition_contains_product', array( $this, 'wafs_match_condition_contains_product' ), 10, 3 );
|
27 |
+
add_action( 'wafs_match_condition_coupon', array( $this, 'wafs_match_condition_coupon' ), 10, 3 );
|
28 |
+
|
29 |
+
add_action( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 );
|
30 |
+
add_action( 'wafs_match_condition_city', array( $this, 'wafs_match_condition_city' ), 10, 3 );
|
31 |
+
add_action( 'wafs_match_condition_state', array( $this, 'wafs_match_condition_state' ), 10, 3 );
|
32 |
+
add_action( 'wafs_match_condition_country', array( $this, 'wafs_match_condition_country' ), 10, 3 );
|
33 |
+
add_action( 'wafs_match_condition_role', array( $this, 'wafs_match_condition_role' ), 10, 3 );
|
34 |
+
|
35 |
+
add_action( 'wafs_match_condition_width', array( $this, 'wafs_match_condition_width' ), 10, 3 );
|
36 |
+
add_action( 'wafs_match_condition_height', array( $this, 'wafs_match_condition_height' ), 10, 3 );
|
37 |
+
add_action( 'wafs_match_condition_length', array( $this, 'wafs_match_condition_length' ), 10, 3 );
|
38 |
+
add_action( 'wafs_match_condition_weight', array( $this, 'wafs_match_condition_weight' ), 10, 3 );
|
39 |
+
add_action( 'wafs_match_condition_stock', array( $this, 'wafs_match_condition_stock' ), 10, 3 );
|
40 |
+
add_action( 'wafs_match_condition_stock_status', array( $this, 'wafs_match_condition_stock_status' ), 10, 3 );
|
41 |
+
add_action( 'wafs_match_condition_backorder', array( $this, 'wafs_match_condition_backorder' ), 10, 3 );
|
42 |
+
add_action( 'wafs_match_condition_category', array( $this, 'wafs_match_condition_category' ), 10, 3 );
|
43 |
+
|
44 |
+
}
|
45 |
+
|
46 |
+
|
47 |
+
/* Match subtotal
|
48 |
+
*
|
49 |
+
* @param bool $match
|
50 |
+
* @param string $operator
|
51 |
+
* @param mixed $value
|
52 |
+
* @return bool
|
53 |
+
*/
|
54 |
+
public function wafs_match_condition_subtotal( $match, $operator, $value ) {
|
55 |
+
|
56 |
+
global $woocommerce;
|
57 |
+
|
58 |
+
if ( ! isset( $woocommerce->cart ) ) return;
|
59 |
+
|
60 |
+
if ( '==' == $operator ) :
|
61 |
+
$match = ( $woocommerce->cart->subtotal == $value );
|
62 |
+
elseif ( '!=' == $operator ) :
|
63 |
+
$match = ( $woocommerce->cart->subtotal != $value );
|
64 |
+
elseif ( '>=' == $operator ) :
|
65 |
+
$match = ( $woocommerce->cart->subtotal >= $value );
|
66 |
+
elseif ( '<=' == $operator ) :
|
67 |
+
$match = ( $woocommerce->cart->subtotal <= $value );
|
68 |
+
endif;
|
69 |
+
|
70 |
+
return $match;
|
71 |
+
|
72 |
+
}
|
73 |
+
|
74 |
+
|
75 |
+
/* Match subtotal excluding taxes
|
76 |
+
*
|
77 |
+
* @param bool $match
|
78 |
+
* @param string $operator
|
79 |
+
* @param mixed $value
|
80 |
+
* @return bool
|
81 |
+
*/
|
82 |
+
public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
|
83 |
+
|
84 |
+
global $woocommerce;
|
85 |
+
|
86 |
+
if ( ! isset( $woocommerce->cart ) ) return;
|
87 |
+
|
88 |
+
if ( '==' == $operator ) :
|
89 |
+
$match = ( $woocommerce->cart->subtotal_ex_tax == $value );
|
90 |
+
elseif ( '!=' == $operator ) :
|
91 |
+
$match = ( $woocommerce->cart->subtotal_ex_tax != $value );
|
92 |
+
elseif ( '>=' == $operator ) :
|
93 |
+
$match = ( $woocommerce->cart->subtotal_ex_tax >= $value );
|
94 |
+
elseif ( '<=' == $operator ) :
|
95 |
+
$match = ( $woocommerce->cart->subtotal_ex_tax <= $value );
|
96 |
+
endif;
|
97 |
+
|
98 |
+
return $match;
|
99 |
+
|
100 |
+
}
|
101 |
+
|
102 |
+
|
103 |
+
/* Match taxes
|
104 |
+
*
|
105 |
+
* @param bool $match
|
106 |
+
* @param string $operator
|
107 |
+
* @param mixed $value
|
108 |
+
* @return bool
|
109 |
+
*/
|
110 |
+
public function wafs_match_condition_tax( $match, $operator, $value ) {
|
111 |
+
|
112 |
+
global $woocommerce;
|
113 |
+
|
114 |
+
if ( ! isset( $woocommerce->cart ) ) return;
|
115 |
+
|
116 |
+
$taxes = array_sum( (array) $woocommerce->cart->taxes );
|
117 |
+
|
118 |
+
if ( '==' == $operator ) :
|
119 |
+
$match = ( $taxes == $value );
|
120 |
+
elseif ( '!=' == $operator ) :
|
121 |
+
$match = ( $taxes != $value );
|
122 |
+
elseif ( '>=' == $operator ) :
|
123 |
+
$match = ( $taxes >= $value );
|
124 |
+
elseif ( '<=' == $operator ) :
|
125 |
+
$match = ( $taxes <= $value );
|
126 |
+
endif;
|
127 |
+
|
128 |
+
return $match;
|
129 |
+
|
130 |
+
}
|
131 |
+
|
132 |
+
|
133 |
+
/* Match quantity
|
134 |
+
*
|
135 |
+
* @param bool $match
|
136 |
+
* @param string $operator
|
137 |
+
* @param mixed $value
|
138 |
+
* @return bool
|
139 |
+
*/
|
140 |
|