WooCommerce Advanced Free Shipping - Version 1.0.3

Version Description

  • Improvement - Customized user messages when saving shipping method
  • Improvement - Updated some comments to comment standards
  • Improvement - Overview not showing all actions when hovering only one
  • Improvement - Added ABSPATH check to each file
  • Improvement - Improved code comments
  • Improvement - Remove globals, use WAFS() function now
  • Improvement - Zipcodes are now better detected (only integer values)
  • Improvement - Load textdomains
  • Improvement - Add compatibility for custom value fields
  • Improvement - Add world wide state support
  • Fix - No notice on shipping title in DEBUG mode
  • Fix - Loading icon on sub directory websites
  • Fix - Condition description didn't show sometimes
  • Fix - 'Category' - 'Not equal to' error
  • Fix - Showing drafts in overview
  • Fix - Change option name from hide_other_shipping_when_available to hide_other_shipping
  • Removed - Author from overview, who needs that?
Download this release

Release Info

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

Code changes from version 1.0.2 to 1.0.3

assets/css/admin-style.css CHANGED
@@ -40,7 +40,7 @@
40
  }
41
 
42
  #wafs_conditions p + p {
43
- display: none;
44
  }
45
  /* Description */
46
  .wafs_desc {
@@ -104,7 +104,7 @@
104
  }
105
 
106
 
107
- /* WooCommerce Add icon */
108
  .add.button:before {
109
  font-family: WooCommerce;
110
  speak: none;
@@ -115,4 +115,11 @@
115
  -webkit-font-smoothing: antialiased;
116
  margin-right: 7px;
117
  content: "\e007";
 
 
 
 
 
 
 
118
  }
40
  }
41
 
42
  #wafs_conditions p + p {
43
+ display: none !important;
44
  }
45
  /* Description */
46
  .wafs_desc {
104
  }
105
 
106
 
107
+ /* WooCommerce Add icon */
108
  .add.button:before {
109
  font-family: WooCommerce;
110
  speak: none;
115
  -webkit-font-smoothing: antialiased;
116
  margin-right: 7px;
117
  content: "\e007";
118
+ }
119
+ /* Overview row actions */
120
+ #advanced_free_shipping_shipping_methods tr .row-actions {
121
+ visibility: hidden;
122
+ }
123
+ #advanced_free_shipping_shipping_methods tr:hover > td > .row-actions {
124
+ visibility: visible !important;
125
  }
assets/js/wafs-js.js CHANGED
@@ -1,6 +1,6 @@
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() {
1
  jQuery( function( $ ) {
2
 
3
+ var loading_icon = '<span class="loading-icon"><img src="images/wpspin_light.gif"/></span>';
4
 
5
  // Add condition
6
  $( '#wafs_conditions' ).on( 'click', '.condition-add', function() {
includes/admin/settings/conditions/class-wafs-condition.php CHANGED
@@ -1,123 +1,198 @@
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.
@@ -138,6 +213,3 @@ require_once plugin_dir_path( __FILE__ ) . 'condition-values.php';
138
  * Load condition descriptions.
139
  */
140
  require_once plugin_dir_path( __FILE__ ) . 'condition-descriptions.php';
141
-
142
-
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
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
+
15
+ class WAFS_Condition {
16
+
17
+ /**
18
+ * Condition.
19
+ *
20
+ * @since 1.0.0
21
+ * @access public
22
+ * @var string $condition Condition slug.
23
+ */
24
  public $condition;
25
+
26
+ /**
27
+ * Operator.
28
+ *
29
+ * @since 1.0.0
30
+ * @access public
31
+ * @var string $operaor operator slug.
32
+ */
33
  public $operator;
34
+
35
+ /**
36
+ * Value.
37
+ *
38
+ * @since 1.0.0
39
+ * @access public
40
+ * @var string $value Condition value.
41
+ */
42
  public $value;
43
+
44
+ /**
45
+ * Group ID.
46
+ *
47
+ * @since 1.0.0
48
+ * @access public
49
+ * @var string $group Condition grou ID.
50
+ */
51
  public $group;
52
+
53
+ /**
54
+ * Condition id.
55
+ *
56
+ * @since 1.0.0
57
+ * @access public
58
+ * @var string $id Condition ID.
59
+ */
60
  public $id;
61
 
62
 
63
  /**
64
+ * Constructor.
65
+ *
66
+ * @since 1.0.0
67
  */
68
  public function __construct( $id = null, $group = 0, $condition = null, $operator = null, $value = null ) {
69
+
70
  $this->id = $id;
71
  $this->group = $group;
72
  $this->condition = $condition;
73
  $this->operator = $operator;
74
  $this->value = $value;
75
+
76
  if ( ! $id )
77
  $this->id = rand();
78
+
79
  $this->wafs_create_object();
80
+
81
  }
82
+
83
+
84
  /**
85
+ * Condition rule.
86
+ *
87
+ * Create an condition rule object.
88
  *
89
+ * @since 1.0.0
90
  */
91
  public function wafs_create_object() {
92
+
93
  ?><div class='wafs-condition-wrap'><?php
94
 
95
+ do_action( 'wafs_before_condition', $this );
96
+
97
  $this->wafs_condition_conditions();
98
  $this->wafs_condition_operator();
99
  $this->wafs_condition_values();
100
+
101
  $this->wafs_add_condition_button();
102
  $this->wafs_remove_condition_button();
103
+
104
  $this->wafs_condition_description();
105
+
106
+ do_action( 'wafs_after_condition', $this );
107
+
108
  ?></div><?php
109
+
110
+ }
111
+
112
+
113
  /**
114
  * Condition dropdown.
115
  *
116
+ * Render and load condition dropdown.
117
+ *
118
+ * @since 1.0.0
119
  */
120
  public function wafs_condition_conditions() {
121
 
122
  wafs_condition_conditions( $this->id, $this->group, $this->condition );
123
+
124
  }
125
+
126
 
127
  /**
128
  * Operator dropdown.
129
  *
130
+ * Render and load operator dropdown.
131
+ *
132
+ * @since 1.0.0
133
  */
134
  public function wafs_condition_operator() {
135
+
136
  wafs_condition_operator( $this->id, $this->group, $this->operator );
137
+
138
  }
139
+
140
 
141
  /**
142
  * Value dropdown.
143
  *
144
+ * Render and load value dropdown.
145
+ *
146
+ * @since 1.0.0
147
  */
148
  public function wafs_condition_values() {
149
 
150
  wafs_condition_values( $this->id, $this->group, $this->condition, $this->value );
151
+
152
  }
153
+
154
+
155
+ /**
156
+ * Add button.
157
+ *
158
+ * Display a add button at the end of the condition rule.
159
+ *
160
+ * @since 1.0.0
161
+ */
162
+ public function wafs_add_condition_button() {
163
  ?>
164
  <a class='button condition-add' data-group='<?php echo $this->group; ?>' href='javascript:void(0);'>+</a>
165
  <?php
166
  }
167
+
168
+
169
+ /**
170
+ * Remove button.
171
+ *
172
+ * Display aa remove button at the end of the condition rule.
173
+ *
174
+ * @since 1.0.0
175
+ */
176
  public function wafs_remove_condition_button() {
177
  ?>
178
  <a class='button condition-delete' href='javascript:void(0);'>-</a>
179
  <?php
180
  }
181
+
182
+
183
+ /**
184
+ * Description.
185
+ *
186
+ * Display an description at the end of the condition rule.
187
+ *
188
+ * @since 1.0.0
189
+ */
190
  public function wafs_condition_description() {
191
+
192
  wafs_condition_description( $this->condition );
193
+
194
  }
195
+
196
  }
197
  /**
198
  * Load condition keys dropdown.
213
  * Load condition descriptions.
214
  */
215
  require_once plugin_dir_path( __FILE__ ) . 'condition-descriptions.php';
 
 
 
includes/admin/settings/conditions/condition-conditions.php CHANGED
@@ -1,67 +1,73 @@
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
- 'category' => __( 'Category', 'wafs' ),
29
  ),
30
  );
31
-
32
  $conditions = apply_filters( 'wafs_conditions', $conditions );
33
-
34
  ?>
35
-
36
  <span class='wafs-condition-wrap wafs-condition-wrap-<?php echo $id; ?>'>
37
-
38
- <select class='wafs-condition' data-group='<?php echo $group; ?>' data-id='<?php echo $id; ?>'
39
  name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][condition]'>
40
-
41
- <?php echo $selected;
42
  foreach ( $conditions as $option_group => $values ) :
43
-
44
  ?><optgroup label='<?php echo $option_group; ?>'><?php
45
-
46
  foreach ( $values as $key => $value ) :
47
-
48
- $selected = ( $key == $current_value ) ? "SELECTED" : null;
49
-
50
- ?><option value='<?php echo $key; ?>' <?php echo $selected; ?>><?php echo $value; ?></option><?php
51
-
52
  endforeach;
53
-
54
  ?></optgroup><?php
55
-
56
  endforeach;
57
  ?>
58
-
59
  </select>
60
-
61
- </span>
62
-
63
- <?php
64
-
65
- }
66
 
67
- ?>
 
 
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
 
4
+ /**
5
+ * Create condition dropdown.
6
+ *
7
+ * Set all conditions and create dropdown for it.
8
+ *
9
+ * @since 1.0.0
10
+ *
11
+ * @param mixed $id Throw in the condition ID.
12
+ * @param midex $group Condition group ID.
13
+ * @param string $current_value Current chosen slug.
14
+ */
15
+ function wafs_condition_conditions( $id, $group = 0, $current_value = 'subtotal' ) {
16
 
17
  $conditions = array(
18
+ __( 'Cart', 'woocommerce-advanced-free-shipping' ) => array(
19
+ 'subtotal' => __( 'Subtotal', 'woocommerce-advanced-free-shipping' ),
20
+ 'subtotal_ex_tax' => __( 'Subtotal ex. taxes', 'woocommerce-advanced-free-shipping' ),
21
+ 'tax' => __( 'Tax', 'woocommerce-advanced-free-shipping' ),
22
+ 'quantity' => __( 'Quantity', 'woocommerce-advanced-free-shipping' ),
23
+ 'contains_product' => __( 'Contains product', 'woocommerce-advanced-free-shipping' ),
24
+ 'coupon' => __( 'Coupon', 'woocommerce-advanced-free-shipping' ),
25
+ 'weight' => __( 'Weight', 'woocommerce-advanced-free-shipping' ),
26
+ 'contains_shipping_class' => __( 'Contains shipping class', 'woocommerce-advanced-free-shipping' ),
27
  ),
28
+ __( 'User Details', 'woocommerce-advanced-free-shipping' ) => array(
29
+ 'zipcode' => __( 'Zipcode', 'woocommerce-advanced-free-shipping' ),
30
+ 'city' => __( 'City', 'woocommerce-advanced-free-shipping' ),
31
+ 'state' => __( 'State', 'woocommerce-advanced-free-shipping' ),
32
+ 'country' => __( 'Country', 'woocommerce-advanced-free-shipping' ),
33
+ 'role' => __( 'User role', 'woocommerce-advanced-free-shipping' ),
34
  ),
35
+ __( 'Product', 'woocommerce-advanced-free-shipping' ) => array(
36
+ 'width' => __( 'Width', 'woocommerce-advanced-free-shipping' ),
37
+ 'height' => __( 'Height', 'woocommerce-advanced-free-shipping' ),
38
+ 'length' => __( 'Length', 'woocommerce-advanced-free-shipping' ),
39
+ 'stock' => __( 'Stock', 'woocommerce-advanced-free-shipping' ),
40
+ 'stock_status' => __( 'Stock status', 'woocommerce-advanced-free-shipping' ),
41
+ 'category' => __( 'Category', 'woocommerce-advanced-free-shipping' ),
 
42
  ),
43
  );
44
+
45
  $conditions = apply_filters( 'wafs_conditions', $conditions );
 
46
  ?>
47
+
48
  <span class='wafs-condition-wrap wafs-condition-wrap-<?php echo $id; ?>'>
49
+
50
+ <select class='wafs-condition' data-group='<?php echo $group; ?>' data-id='<?php echo $id; ?>'
51
  name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][condition]'>
52
+
53
+ <?php
54
  foreach ( $conditions as $option_group => $values ) :
55
+
56
  ?><optgroup label='<?php echo $option_group; ?>'><?php
57
+
58
  foreach ( $values as $key => $value ) :
59
+
60
+ ?><option value='<?php echo $key; ?>' <?php selected( $key, $current_value ); ?>><?php echo $value; ?></option><?php
61
+
 
 
62
  endforeach;
63
+
64
  ?></optgroup><?php
65
+
66
  endforeach;
67
  ?>
68
+
69
  </select>
 
 
 
 
 
 
70
 
71
+ </span><?php
72
+
73
+ }
includes/admin/settings/conditions/condition-descriptions.php CHANGED
@@ -1,44 +1,49 @@
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
- if ( !isset( $descriptions[ $condition ] ) ) :
 
21
  return;
22
  endif;
23
- ?>
24
- <span class='wafs-description <?php echo $descriptions[ $condition ]; ?>-description'>
25
 
26
  <div class='description'>
27
-
28
- <?php if ( isset( $descriptions[ $condition ] ) ) : ?>
29
-
30
- <img class='wafs_tip' src='<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png' height='24' width='24' />
31
-
32
- <div class='wafs_desc'>
33
- <?php echo $descriptions[ $condition ]; ?>
34
- </div>
35
-
36
- <?php endif; ?>
37
-
38
  </div>
39
-
40
- </span>
41
- <?php
42
 
43
  }
44
- ?>
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
 
4
+ /**
5
+ * Descriptions.
6
+ *
7
+ * Display a description icon + tooltip on hover.
8
+ *
9
+ * @since 1.0.0
10
+ *
11
+ * @param string $condition Condition to show description for.
12
+ */
13
  function wafs_condition_description( $condition ) {
14
 
 
 
15
  $descriptions = array(
16
+ 'state' => __( 'States must be installed in WC.', 'woocommerce-advanced-free-shipping' ),
17
+ 'weight' => __( 'Weight calculated on all the cart contents', 'woocommerce-advanced-free-shipping' ),
18
+ 'length' => __( 'Compared to lengthiest product in cart', 'woocommerce-advanced-free-shipping' ),
19
+ 'width' => __( 'Compared to widest product in cart', 'woocommerce-advanced-free-shipping' ),
20
+ 'height' => __( 'Compared to highest product in cart', 'woocommerce-advanced-free-shipping' ),
21
+ 'stock_status' => __( 'All products in cart must match stock status', 'woocommerce-advanced-free-shipping' ),
22
+ 'category' => __( 'All products in cart must match category', 'woocommerce-advanced-free-shipping' ),
23
+ 'contains_product' => __( 'Cart must contain one of this product', 'woocommerce-advanced-free-shipping' ),
24
+ 'contains_shipping_class' => __( 'Cart must contain at least one product with the selected shipping class', 'woocommerce-advanced-free-shipping' ),
25
  );
26
+
27
+ $descriptions = apply_filters( 'wafs_descriptions', $descriptions );
28
+
29
  // Display description
30
+ if ( ! isset( $descriptions[ $condition ] ) ) :
31
+ ?><span class='wafs-description no-description'></span><?php
32
  return;
33
  endif;
34
+
35
+ ?><span class='wafs-description <?php echo $condition; ?>-description'>
36
 
37
  <div class='description'>
38
+
39
+ <img class='wafs_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' />
40
+
41
+ <div class='wafs_desc'>
42
+ <?php echo $descriptions[ $condition ]; ?>
43
+ </div>
44
+
 
 
 
 
45
  </div>
46
+
47
+ </span><?php
 
48
 
49
  }
 
includes/admin/settings/conditions/condition-operators.php CHANGED
@@ -1,37 +1,40 @@
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
- ?>
 
 
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
 
4
+ /**
5
+ * Create operator dropdown.
6
+ *
7
+ * Set all operators and create dropdown for it.
8
+ *
9
+ * @since 1.0.0
10
+ *
11
+ * @param int $id Throw in the condition ID.
12
+ * @param int $group Condition group ID.
13
+ * @param string $current_value Current chosen slug.
14
+ */
15
  function wafs_condition_operator( $id, $group = 0, $current_value = '==' ) {
16
+
17
  $operators = array(
18
+ '==' => __( 'Equal to', 'woocommerce-advanced-free-shipping' ),
19
+ '!=' => __( 'Not equal to', 'woocommerce-advanced-free-shipping' ),
20
+ '>=' => __( 'Greater or equal to', 'woocommerce-advanced-free-shipping' ),
21
+ '<=' => __( 'Less or equal to ', 'woocommerce-advanced-free-shipping' ),
22
  );
23
+
24
  $operators = apply_filters( 'wafs_operators', $operators );
25
+
26
+ ?><span class='wafs-operator-wrap wafs-operator-wrap-<?php echo $id; ?>'>
27
+
 
 
28
  <select id='' class='wafs-operator' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][operator]'>
29
+
30
+ <?php foreach ( $operators as $key => $value ) :
31
+
32
+ ?><option value='<?php echo $key; ?>' <?php selected( $key, $current_value ); ?>><?php echo $value; ?></option><?php
33
+
34
+ endforeach; ?>
35
+
 
 
 
36
  </select>
 
 
 
 
 
 
37
 
38
+ </span><?php
39
+
40
+ }
includes/admin/settings/conditions/condition-values.php CHANGED
@@ -1,192 +1,250 @@
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 'category' :
136
-
137
  $values['field'] = 'select';
138
-
139
  $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
140
  foreach ( $categories as $category ) :
141
- $values['values'][ $category->slug ] = $category->name;
142
  endforeach;
143
-
144
  break;
145
 
146
-
147
  endswitch;
148
 
149
  $values = apply_filters( 'wafs_values', $values, $condition );
150
- ?>
151
-
152
- <span class='wafs-value-wrap wafs-value-wrap-<?php echo $id; ?>'>
153
-
154
- <?php
155
  switch ( $values['field'] ) :
156
-
157
  case 'text' :
158
- ?>
159
- <input type='text' class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'
160
- placeholder='<?php echo @$values['placeholder']; ?>' value='<?php echo $current_value; ?>'>
161
- <?php
162
  break;
163
-
164
- case 'number' :
165
- ?>
166
- <input type='text' class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'
167
- min='<?php echo @$values['min']; ?>' max='<?php echo @$values['max']; ?>' placeholder='<?php echo @$values['placeholder']; ?>'
168
- value='<?php echo $current_value; ?>'>
169
- <?php
170
  break;
171
-
172
- default :
173
  case 'select' :
174
- ?><select class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'><?php
175
- foreach ( $values['values'] as $key => $value ) :
176
- $selected = ( $key == $current_value ) ? 'SELECTED' : null;
177
- ?><option value='<?php echo $key; ?>' <?php echo $selected; ?>><?php echo $value; ?></option><?php
178
- endforeach;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  ?></select><?php
 
180
  break;
181
-
 
 
 
 
182
  endswitch;
183
-
184
- ?>
185
-
186
- </span>
187
-
188
- <?php
189
-
190
- }
191
 
192
- ?>
 
 
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+
4
+ /**
5
+ * Create value input.
6
+ *
7
+ * Set all value and create an input field for it.
8
+ *
9
+ * @since 1.0.0
10
+ *
11
+ * @param int $id Throw in the condition ID.
12
+ * @param int $group Condition group ID.
13
+ * @param string $condition Condition where the value input is used for.
14
+ * @param string $current_value Current chosen slug.
15
+ */
16
  function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $current_value = '' ) {
17
 
18
  global $woocommerce;
19
 
20
+ // Defaults
21
+ $values = array( 'placeholder' => '', 'min' => '', 'max' => '', 'field' => 'text', 'options' => array() );
22
+
23
  switch ( $condition ) :
24
+
25
  default:
26
  case 'subtotal' :
27
+
28
  $values['field'] = 'number';
29
+
30
  break;
31
+
32
  case 'subtotal_ex_tax' :
33
+
34
  $values['field'] = 'number';
35
+
36
  break;
37
 
38
  case 'tax' :
39
+
40
  $values['field'] = 'number';
41
+
42
  break;
43
+
44
  case 'quantity' :
45
+
46
  $values['field'] = 'number';
47
+
48
  break;
49
+
50
  case 'contains_product' :
51
+
52
  $values['field'] = 'select';
53
 
54
  $products = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'product', 'order' => 'asc', 'orderby' => 'title' ) );
55
  foreach ( $products as $product ) :
56
+ $values['options'][$product->ID ] = $product->post_title;
57
  endforeach;
58
+
59
  break;
60
+
61
  case 'coupon' :
62
+
63
  $values['field'] = 'text';
64
+
65
+ break;
66
+
67
+ case 'weight' :
68
+
69
+ $values['field'] = 'text';
70
+
71
+ break;
72
+
73
+ case 'contains_shipping_class' :
74
+
75
+ $values['field'] = 'select';
76
+ $values['options']['-1'] = __( 'No shipping class', 'woocommerce' );
77
+
78
+ // Get all shipping classes
79
+ foreach ( get_terms( 'product_shipping_class', array( 'hide_empty' => false ) ) as $shipping_class ) :
80
+ $values['options'][ $shipping_class->slug ] = $shipping_class->name;
81
+ endforeach;
82
+
83
  break;
84
 
85
  /**
86
  * User details
87
  */
88
+
89
  case 'zipcode' :
90
+
91
  $values['field'] = 'text';
92
+
93
  break;
94
 
95
  case 'city' :
96
+
97
  $values['field'] = 'text';
98
+
99
  break;
100
+
101
  case 'state' :
102
+
103
  $values['field'] = 'select';
104
+
105
+ foreach ( $woocommerce->countries->states as $country => $states ) :
106
+
107
+ if ( empty( $states ) ) continue; // Don't show country if it has no states
108
+ if ( ! array_key_exists( $country, $woocommerce->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries
109
+
110
+ foreach ( $states as $state_key => $state ) :
111
+ $country_states[ $woocommerce->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state;
112
+ endforeach;
113
+
114
+ $values['options'] = $country_states;
115
+
116
+ endforeach;
117
+
118
  break;
119
 
120
  case 'country' :
121
 
122
  $values['field'] = 'select';
123
+ $values['options'] = $woocommerce->countries->get_allowed_countries();
124
+
125
  break;
126
+
127
  case 'role' :
128
+
129
  $values['field'] = 'select';
130
  $roles = array_keys( get_editable_roles() );
131
+ $values['options'] = array_combine( $roles, $roles );
132
+
133
  break;
134
+
135
  /**
136
  * Product
137
  */
138
+
139
  case 'width' :
140
+
141
  $values['field'] = 'text';
142
+
143
  break;
144
 
145
+
146
  case 'height' :
147
+
148
  $values['field'] = 'text';
149
+
150
  break;
151
 
152
+
153
  case 'length' :
154
+
 
 
 
 
 
 
155
  $values['field'] = 'text';
156
+
157
  break;
158
 
159
  case 'stock' :
160
+
161
  $values['field'] = 'text';
162
+
163
  break;
164
+
165
+ case 'stock_status' :
166
+
167
  $values['field'] = 'select';
168
+ $values['options'] = array(
169
+ 'instock' => __( 'In stock', 'woocommerce-advanced-free-shipping' ),
170
+ 'outofstock' => __( 'Out of stock', 'woocommerce-advanced-free-shipping' ),
171
  );
172
+
173
  break;
174
 
175
  case 'category' :
176
+
177
  $values['field'] = 'select';
178
+
179
  $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) );
180
  foreach ( $categories as $category ) :
181
+ $values['options'][ $category->slug ] = $category->name;
182
  endforeach;
183
+
184
  break;
185
 
186
+
187
  endswitch;
188
 
189
  $values = apply_filters( 'wafs_values', $values, $condition );
190
+
191
+ ?><span class='wafs-value-wrap wafs-value-wrap-<?php echo $id; ?>'><?php
192
+
 
 
193
  switch ( $values['field'] ) :
194
+
195
  case 'text' :
196
+
197
+ ?><input type='text' class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'
198
+ placeholder='<?php echo @$values['placeholder']; ?>' value='<?php echo $current_value; ?>'><?php
199
+
200
  break;
201
+
202
+ case 'number' :
203
+
204
+ ?><input type='text' class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'
205
+ min='<?php echo @$values['min']; ?>' max='<?php echo @$values['max']; ?>' placeholder='<?php echo @$values['placeholder']; ?>'
206
+ value='<?php echo $current_value; ?>'><?php
207
+
208
  break;
209
+
 
210
  case 'select' :
211
+
212
+ // Backwards compatibility for extensions
213
+ @array_merge( $values['options'], $values['values'] );
214
+ ?><select class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][value]'>
215
+
216
+ <option <?php selected( '', $current_value ); ?>><?php _e( 'Select option' , 'woocommerce-advanced-free-shipping' ); ?></option><?php
217
+ foreach ( $values['options'] as $key => $value ) :
218
+
219
+ if ( ! is_array( $value ) ) :
220
+ ?><option value='<?php echo $key; ?>' <?php selected( $key, $current_value ); ?>><?php echo $value; ?></option><?php
221
+ else :
222
+ ?><optgroup label='<?php echo $key ?>'><?php
223
+ foreach ( $value as $k => $v ) :
224
+ ?><option value='<?php echo $k; ?>' <?php selected( $k, $current_value ); ?>><?php echo $v; ?></option><?php
225
+ endforeach;
226
+ ?></optgroup><?php
227
+
228
+ endif;
229
+
230
+ endforeach;
231
+
232
+ if ( empty( $values['options'] ) ) :
233
+ ?><option readonly disabled><?php
234
+ _e( 'There are no options available', 'woocommerce-advanced-free-shipping' );
235
+ ?></option><?php
236
+ endif;
237
+
238
  ?></select><?php
239
+
240
  break;
241
+
242
+ default :
243
+ do_action( 'wafs_conditino_value_field_type_' . $values['field'], $values );
244
+ break;
245
+
246
  endswitch;
 
 
 
 
 
 
 
 
247
 
248
+ ?></span><?php
249
+
250
+ }
includes/admin/settings/meta-box-conditions.php CHANGED
@@ -1,14 +1,16 @@
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;
@@ -17,38 +19,36 @@ $conditions = get_post_meta( $post->ID, '_wafs_shipping_method_conditions', true
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>
1
  <?php
2
  /**
3
+ * WAFS meta box conditions.
4
  *
5
+ * Display the shipping conditions in the meta box.
6
  *
7
  * @author Jeroen Sormani
8
  * @package WooCommerce Advanced Free Shipping
9
  * @version 1.0.0
10
  */
11
 
12
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13
+
14
  wp_nonce_field( 'wafs_conditions_meta_box', 'wafs_conditions_meta_box_nonce' );
15
 
16
  global $post;
19
  ?>
20
  <div class='wafs wafs_conditions wafs_meta_box wafs_conditions_meta_box'>
21
 
22
+ <p><strong><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong></p>
23
+
24
+ <?php if ( !empty( $conditions ) ) :
 
25
 
26
  foreach ( $conditions as $condition_group => $conditions ) :
 
 
27
 
28
+ ?><div class='condition-group condition-group-<?php echo $condition_group; ?>' data-group='<?php echo $condition_group; ?>'>
29
+
30
+ <p class='or_match'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' );?></p>
31
  <?php
32
  foreach ( $conditions as $condition_id => $condition ) :
33
+
34
  new Wafs_Condition( $condition_id, $condition_group, $condition['condition'], $condition['operator'], $condition['value'] );
35
+
36
  endforeach;
37
  ?>
38
  </div>
39
+
40
+ <p><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
41
+
42
  endforeach;
43
+
44
  else :
45
+
46
  ?><div class='condition-group condition-group-0' data-group='0'><?php
47
  new Wafs_Condition();
48
  ?></div><?php
49
+
50
+ endif; ?>
 
51
 
52
  </div>
53
 
54
+ <a class='button condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'woocommerce-advanced-free-shipping' ); ?></a>
includes/admin/settings/meta-box-settings.php CHANGED
@@ -1,31 +1,30 @@
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
- ?>
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
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13
+
14
  wp_nonce_field( 'wafs_settings_meta_box', 'wafs_settings_meta_box_nonce' );
15
 
16
  global $post;
17
+ $settings = get_post_meta( $post->ID, '_wafs_shipping_method', true );
18
  ?>
19
  <div class='wafs wafs_settings wafs_meta_box wafs_settings_meta_box'>
20
+
21
  <p class='wafs-option'>
22
+
23
+ <label for='shipping_title'><?php _e( 'Shipping title', 'woocommerce-advanced-free-shipping' ); ?></label>
24
+ <input type='text' class='' id='shipping_title' name='_wafs_shipping_method[shipping_title]'
25
+ value='<?php echo @$settings['shipping_title']; ?>' placeholder='<?php _e( 'e.g. Free Shipping', 'woocommerce-advanced-free-shipping' ); ?>'>
26
+
27
  </p>
 
28
 
 
 
29
 
30
+ </div>
includes/admin/views/conditions-table.php CHANGED
@@ -1,79 +1,80 @@
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>
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
+
12
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13
+
14
+ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'wafs', 'post_status' => array( 'draft', 'publish' ) ) );
15
  ?>
16
  <tr valign="top">
17
  <th scope="row" class="titledesc">
18
+ <?php _e( 'Method conditions', 'woocommerce-advanced-free-shipping' ); ?>:<br />
19
+ <!-- <small>Read more</small> -->
20
  </th>
21
+ <td class="forminp" id="<?php echo $this->id; ?>_shipping_methods">
22
 
23
  <table class='wp-list-table wafs-table widefat'>
24
  <thead>
25
  <tr>
26
+ <th style='padding-left: 10px;'><?php _e( 'Title', 'woocommerce-advanced-free-shipping' ); ?></th>
27
+ <th style='padding-left: 10px;'><?php _e( 'Shipping title', 'woocommerce-advanced-free-shipping' ); ?></th>
28
+ <th style='padding-left: 10px;'><?php _e( 'Condition groups', 'woocommerce-advanced-free-shipping' ); ?></th>
 
29
  </tr>
30
  </thead>
31
  <tbody>
32
  <?php
33
  foreach ( $method_conditions as $method_condition ) :
34
+
35
  $method_details = get_post_meta( $method_condition->ID, '_wafs_shipping_method', true );
36
  $conditions = get_post_meta( $method_condition->ID, '_wafs_shipping_method_conditions', true );
37
+
38
+ ?><tr>
39
  <td>
40
  <strong>
41
+ <a href='<?php echo get_edit_post_link( $method_condition->ID ); ?>' class='row-title' title='<?php _e( 'Edit Method', 'woocommerce-advanced-free-shipping' ); ?>'>
42
+ <?php echo $method_condition->post_title; echo empty( $method_condition->post_title) ? __( 'Untitled', 'woocommerce-advanced-free-shipping' ) : null; ?>
43
  </a>
44
  </strong>
45
  <div class='row-actions'>
46
  <span class='edit'>
47
+ <a href='<?php echo get_edit_post_link( $method_condition->ID ); ?>' title='<?php _e( 'Edit Method', 'woocommerce-advanced-free-shipping' ); ?>'>
48
+ <?php _e( 'Edit', 'woocommerce-advanced-free-shipping' ); ?>
49
  </a>
50
  |
51
  </span>
52
  <span class='trash'>
53
+ <a href='<?php echo get_delete_post_link( $method_condition->ID ); ?>' title='<?php _e( 'Delete Method', 'woocommerce-advanced-free-shipping' ); ?>'>
54
+ <?php _e( 'Delete', 'woocommerce-advanced-free-shipping' ); ?>
55
  </a>
56
  </span>
57
  </div>
58
  </td>
59
+ <td><?php echo empty( $method_details['shipping_title'] ) ? __( 'Free Shipping', 'woocommerce-advanced-free-shipping') : $method_details['shipping_title']; ?></td>
60
  <td><?php echo count( $conditions ); ?></td>
 
61
  </td>
62
+ </tr><?php
63
+
64
  endforeach;
65
+
66
  if ( empty( $method_conditions ) ) :
67
  ?>
68
  <tr>
69
+ <td colspan='2'><?php _e( 'There are no Free Shipping methods. Yet...', 'woocommerce-advanced-free-shipping' ); ?></td>
70
  </tr>
71
+ <?php endif; ?>
72
+
 
73
  </tbody>
74
  <tfoot>
75
  <tr>
76
  <th colspan='4' style='padding-left: 10px;'>
77
+ <a href='<?php echo admin_url( 'post-new.php?post_type=wafs' ); ?>' class='add button'><?php _e( 'Add Free Shipping Method', 'woocommerce-advanced-free-shipping' ); ?></a>
78
  </th>
79
  </tr>
80
  </tfoot>
includes/class-wafs-ajax.php CHANGED
@@ -1,85 +1,107 @@
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();
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
  /**
4
+ * Class WAFS_Ajax.
5
  *
6
+ * Initialize the WAFS post type.
7
  *
8
+ * @class WAFS_Ajax
9
  * @author Jeroen Sormani
10
  * @package WooCommerce Advanced Free Shipping
11
  * @version 1.0.0
12
  */
13
+ class WAFS_Ajax {
14
 
15
 
16
+ /**
17
+ * Constructor.
18
  *
19
  * Add ajax actions in order to work.
20
+ *
21
+ * @since 1.0.0
22
  */
23
  public function __construct() {
24
+
25
  // Add elements
26
  add_action( 'wp_ajax_wafs_add_condition', array( $this, 'wafs_add_condition' ) );
27
  add_action( 'wp_ajax_wafs_add_condition_group', array( $this, 'wafs_add_condition_group' ) );
28
+
29
  // Update elements
30
  add_action( 'wp_ajax_wafs_update_condition_value', array( $this, 'wafs_update_condition_value' ) );
31
  add_action( 'wp_ajax_wafs_update_condition_description', array( $this, 'wafs_update_condition_description' ) );
32
+
33
  }
34
+
35
+
36
+ /**
37
+ * Add condition.
38
+ *
39
+ * Create a new WAS_Condition class and render.
40
+ *
41
+ * @since 1.0.0
42
  */
43
  public function wafs_add_condition() {
44
 
45
+ new WAFS_Condition( null, $_POST['group'] );
46
  die();
47
+
48
  }
49
+
50
+
51
+ /**
52
+ * Condition group.
53
+ *
54
  * Render new condition group.
55
+ *
56
+ * @since 1.0.0
57
  */
58
  public function wafs_add_condition_group() {
59
  ?>
60
  <div class='condition-group condition-group-<?php echo $_POST['group']; ?>' data-group='<?php echo $_POST['group']; ?>'>
61
+
62
+ <p class='or_match'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' );?></p>
63
+ <?php
64
+ new WAFS_Condition( null, $_POST['group'] );
65
  ?>
66
 
67
  </div>
68
 
69
+ <p><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p>
70
+
71
  <?php
72
  die();
73
  }
74
+
75
+
76
+ /**
77
+ * Update values.
78
+ *
79
+ * Retreive and render the new condition values according to the condition key.
80
  *
81
+ * @since 1.0.0
82
  */
83
  public function wafs_update_condition_value() {
84
 
85
  wafs_condition_values( $_POST['id'], $_POST['group'], $_POST['condition'] );
86
  die();
87
+
88
  }
89
+
90
+
91
+ /**
92
+ * Update description.
93
+ *
94
+ * Render the corresponding description for the condition key.
95
  *
96
+ * @since 1.0.0
97
  */
98
  public function wafs_update_condition_description() {
99
+
100
  wafs_condition_description( $_POST['condition'] );
101
  die();
102
+
103
  }
104
+
105
 
106
  }
107
+ new WAFS_Ajax();
includes/class-wafs-match-conditions.php CHANGED
@@ -1,61 +1,70 @@
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_category', array( $this, 'wafs_match_condition_category' ), 10, 3 );
42
-
43
  }
44
 
45
 
46
- /* Match subtotal
 
 
 
 
 
47
  *
48
- * @param bool $match
49
- * @param string $operator
50
- * @param mixed $value
51
- * @return bool
 
 
52
  */
53
  public function wafs_match_condition_subtotal( $match, $operator, $value ) {
54
 
55
  global $woocommerce;
56
 
57
  if ( ! isset( $woocommerce->cart ) ) return;
58
-
59
  if ( '==' == $operator ) :
60
  $match = ( $woocommerce->cart->subtotal == $value );
61
  elseif ( '!=' == $operator ) :
@@ -65,23 +74,30 @@ class Wafs_Match_Conditions {
65
  elseif ( '<=' == $operator ) :
66
  $match = ( $woocommerce->cart->subtotal <= $value );
67
  endif;
68
-
69
  return $match;
70
-
71
  }
72
 
73
 
74
- /* Match subtotal excluding taxes
 
 
 
 
 
75
  *
76
- * @param bool $match
77
- * @param string $operator
78
- * @param mixed $value
79
- * @return bool
 
 
80
  */
81
  public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
82
 
83
  global $woocommerce;
84
-
85
  if ( ! isset( $woocommerce->cart ) ) return;
86
 
87
  if ( '==' == $operator ) :
@@ -93,23 +109,30 @@ class Wafs_Match_Conditions {
93
  elseif ( '<=' == $operator ) :
94
  $match = ( $woocommerce->cart->subtotal_ex_tax <= $value );
95
  endif;
96
-
97
  return $match;
98
-
99
  }
100
-
101
 
102
- /* Match taxes
 
 
 
 
 
 
103
  *
104
- * @param bool $match
105
- * @param string $operator
106
- * @param mixed $value
107
- * @return bool
 
 
108
  */
109
  public function wafs_match_condition_tax( $match, $operator, $value ) {
110
 
111
  global $woocommerce;
112
-
113
  if ( ! isset( $woocommerce->cart ) ) return;
114
 
115
  $taxes = array_sum( (array) $woocommerce->cart->taxes );
@@ -123,25 +146,33 @@ class Wafs_Match_Conditions {
123
  elseif ( '<=' == $operator ) :
124
  $match = ( $taxes <= $value );
125
  endif;
126
-
127
  return $match;
128
-
129
  }
130
-
131
 
132
- /* Match quantity
 
 
 
 
 
133
  *
134
- * @param bool $match
135
- * @param string $operator
136
- * @param mixed $value
137
- * @return bool
 
 
 
 
138
  */
139
  public function wafs_match_condition_quantity( $match, $operator, $value ) {
140
 
141
  global $woocommerce;
142
-
143
  if ( ! isset( $woocommerce->cart ) ) return;
144
-
145
  if ( '==' == $operator ) :
146
  $match = ( $woocommerce->cart->cart_contents_count == $value );
147
  elseif ( '!=' == $operator ) :
@@ -151,192 +182,317 @@ class Wafs_Match_Conditions {
151
  elseif ( '<=' == $operator ) :
152
  $match = ( $woocommerce->cart->cart_contents_count <= $value );
153
  endif;
154
-
155
  return $match;
156
-
157
  }
158
-
159
 
160
- /* Match quantity
 
 
161
  *
162
- * @param bool $match
163
- * @param string $operator
164
- * @param mixed $value
165
- * @return bool
 
 
 
 
 
 
166
  */
167
  public function wafs_match_condition_contains_product( $match, $operator, $value ) {
168
 
169
  global $woocommerce;
170
-
171
  if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
172
-
173
  foreach ( $woocommerce->cart->cart_contents as $product ) :
174
  $product_ids[] = $product['product_id'];
175
  endforeach;
176
-
177
  if ( '==' == $operator ) :
178
  $match = ( in_array( $value, $product_ids ) );
179
  elseif ( '!=' == $operator ) :
180
  $match = ( ! in_array( $value, $product_ids ) );
181
  endif;
182
-
183
  return $match;
184
-
185
  }
186
-
187
 
188
- /* Match coupon
 
 
 
 
189
  *
190
- * @param bool $match
191
- * @param string $operator
192
- * @param mixed $value
193
- * @return bool
 
 
 
 
194
  */
195
  public function wafs_match_condition_coupon( $match, $operator, $value ) {
196
 
197
  global $woocommerce;
198
-
199
  if ( ! isset( $woocommerce->cart ) ) return;
200
-
201
  if ( '==' == $operator ) :
202
  $match = ( in_array( $value, $woocommerce->cart->applied_coupons ) );
203
  elseif ( '!=' == $operator ) :
204
  $match = ( ! in_array( $value, $woocommerce->cart->applied_coupons ) );
205
  endif;
206
-
207
  return $match;
208
-
209
  }
210
 
211
-
212
- /***************************
213
- *
214
- * User details
215
- *
216
- ***************************
217
- */
218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
- /* Match zipcode
 
 
 
 
221
  *
222
- * @since 1.0.2; $value may contain single or comma (,) separated zipcodes
223
  *
224
- * @param bool $match
225
- * @param string $operator
226
- * @param mixed $value
227
- * @return bool
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  */
229
  public function wafs_match_condition_zipcode( $match, $operator, $value ) {
230
 
231
  global $woocommerce;
232
-
233
- if ( !isset( $woocommerce->customer ) ) return;
234
 
235
  if ( '==' == $operator ) :
236
 
237
- if ( preg_match( '/\,(\s)?/', $value ) ) :
238
- $match = ( in_array( $woocommerce->customer->get_shipping_postcode(), explode( ',', $value ) ) );
239
  else :
240
- $match = ( $woocommerce->customer->get_shipping_postcode() == $value );
241
  endif;
242
 
243
  elseif ( '!=' == $operator ) :
244
 
245
- if ( preg_match( '/\,/', $value ) ) :
246
- $match = ( !in_array( $woocommerce->customer->get_shipping_postcode(), explode( ',', $value ) ) );
247
  else :
248
- $match = ( $woocommerce->customer->get_shipping_postcode() != $value );
249
  endif;
250
 
251
  elseif ( '>=' == $operator ) :
252
- $match = ( $woocommerce->customer->get_shipping_postcode() >= $value );
253
  elseif ( '<=' == $operator ) :
254
- $match = ( $woocommerce->customer->get_shipping_postcode() <= $value );
255
  endif;
256
-
257
  return $match;
258
-
259
  }
260
 
261
 
262
- /* Match city
 
 
 
263
  *
264
- * @param bool $match
265
- * @param string $operator
266
- * @param mixed $value
267
- * @return bool
 
 
 
 
268
  */
269
  public function wafs_match_condition_city( $match, $operator, $value ) {
270
 
271
  global $woocommerce;
272
-
273
  if ( ! isset( $woocommerce->customer ) ) return;
274
-
275
  if ( '==' == $operator ) :
276
  $match = ( preg_match( "/^$value$/i", $woocommerce->customer->get_shipping_city() ) );
277
  elseif ( '!=' == $operator ) :
278
  $match = ( ! preg_match( "/^$value$/i", $woocommerce->customer->get_shipping_city() ) );
279
  endif;
280
-
281
  return $match;
282
-
283
  }
284
-
285
-
286
- /* Match state
287
- *
288
- * @param bool $match
289
- * @param string $operator
290
- * @param mixed $value
291
- * @return bool
292
- */
 
 
 
 
 
 
 
293
  public function wafs_match_condition_state( $match, $operator, $value ) {
294
 
295
  global $woocommerce;
296
-
297
  if ( ! isset( $woocommerce->customer ) ) return;
298
-
 
 
299
  if ( '==' == $operator ) :
300
- $match = ( $woocommerce->customer->get_shipping_state() == $value );
301
  elseif ( '!=' == $operator ) :
302
- $match = ( $woocommerce->customer->get_shipping_state() != $value );
303
  endif;
304
-
305
  return $match;
306
-
307
  }
308
-
309
-
310
- /* Match city
311
- *
312
- * @param bool $match
313
- * @param string $operator
314
- * @param mixed $value
315
- * @return bool
 
 
 
 
 
 
 
316
  */
317
  public function wafs_match_condition_country( $match, $operator, $value ) {
318
 
319
  global $woocommerce;
320
-
321
  if ( ! isset( $woocommerce->customer ) ) return;
322
-
323
  if ( '==' == $operator ) :
324
  $match = ( preg_match( "/^$value$/i", $woocommerce->customer->get_shipping_country() ) );
325
  elseif ( '!=' == $operator ) :
326
  $match = ( ! preg_match( "/^$value$/i", $woocommerce->customer->get_shipping_country() ) );
327
  endif;
328
-
329
  return $match;
330
-
331
  }
332
-
333
 
334
- /* Match role
 
 
 
 
 
 
335
  *
336
- * @param bool $match
337
- * @param string $operator
338
- * @param mixed $value
339
- * @return bool
 
 
 
340
  */
341
  public function wafs_match_condition_role( $match, $operator, $value ) {
342
 
@@ -347,38 +503,40 @@ class Wafs_Match_Conditions {
347
  elseif ( '!=' == $operator ) :
348
  $match = ( ! array_key_exists( $value, $current_user->caps ) );
349
  endif;
350
-
351
  return $match;
352
-
353
  }
354
-
355
 
356
- /***************************
357
- *
358
- * Product
359
- *
360
- ***************************
361
- */
362
 
 
 
 
363
 
364
- /* Match width
 
 
 
 
 
 
365
  *
366
- * Match the user value to the widest product
367
  *
368
- * @param bool $match
369
- * @param string $operator
370
- * @param mixed $value
371
- * @return bool
372
  */
373
  public function wafs_match_condition_width( $match, $operator, $value ) {
374
 
375
  global $woocommerce;
376
-
377
  if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
378
-
379
  foreach ( $woocommerce->cart->cart_contents as $product ) :
380
 
381
- if ( true == $product['data']->variation_has_width ) :
382
  $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) );
383
  else :
384
  $width[] = ( get_post_meta( $product['product_id'], '_width', true ) );
@@ -387,7 +545,7 @@ class Wafs_Match_Conditions {
387
  endforeach;
388
 
389
  $max_width = max( (array) $width );
390
-
391
  if ( '==' == $operator ) :
392
  $match = ( $max_width == $value );
393
  elseif ( '!=' == $operator ) :
@@ -399,29 +557,33 @@ class Wafs_Match_Conditions {
399
  endif;
400
 
401
  return $match;
402
-
403
  }
404
 
405
-
406
- /* Match height
 
 
 
407
  *
408
- * Match the user value to the highest product
409
  *
410
- * @param bool $match
411
- * @param string $operator
412
- * @param mixed $value
413
- * @return bool
 
 
414
  */
415
-
416
  public function wafs_match_condition_height( $match, $operator, $value ) {
417
 
418
  global $woocommerce;
419
-
420
  if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
421
-
422
  foreach ( $woocommerce->cart->cart_contents as $product ) :
423
 
424
- if ( true == $product['data']->variation_has_height ) :
425
  $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) );
426
  else :
427
  $height[] = ( get_post_meta( $product['product_id'], '_height', true ) );
@@ -430,7 +592,7 @@ class Wafs_Match_Conditions {
430
  endforeach;
431
 
432
  $max_height = max( $height );
433
-
434
  if ( '==' == $operator ) :
435
  $match = ( $max_height == $value );
436
  elseif ( '!=' == $operator ) :
@@ -440,31 +602,35 @@ class Wafs_Match_Conditions {
440
  elseif ( '<=' == $operator ) :
441
  $match = ( $max_height <= $value );
442
  endif;
443
-
444
  return $match;
445
-
446
  }
447
-
448
-
449
- /* Match length
 
 
 
450
  *
451
- * Match the user value to the biggest product
452
  *
453
- * @param bool $match
454
- * @param string $operator
455
- * @param mixed $value
456
- * @return bool
 
 
457
  */
458
-
459
  public function wafs_match_condition_length( $match, $operator, $value ) {
460
 
461
  global $woocommerce;
462
-
463
  if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
464
-
465
  foreach ( $woocommerce->cart->cart_contents as $product ) :
466
 
467
- if ( true == $product['data']->variation_has_length ) :
468
  $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) );
469
  else :
470
  $length[] = ( get_post_meta( $product['product_id'], '_length', true ) );
@@ -482,64 +648,43 @@ class Wafs_Match_Conditions {
482
  $match = ( $max_length >= $value );
483
  elseif ( '<=' == $operator ) :
484
  $match = ( $max_length <= $value );
485
- endif;
486
-
487
  return $match;
488
-
489
  }
490
-
491
-
492
- /* Match weight
493
- *
494
- * @param bool $match
495
- * @param string $operator
496
- * @param mixed $value
497
- * @return bool
498
- */
499
- public function wafs_match_condition_weight( $match, $operator, $value ) {
500
 
501
- global $woocommerce;
502
 
503
- if ( ! isset( $woocommerce->cart ) ) return;
504
-
505
- if ( '==' == $operator ) :
506
- $match = ( $woocommerce->cart->cart_contents_weight == $value );
507
- elseif ( '!=' == $operator ) :
508
- $match = ( $woocommerce->cart->cart_contents_weight != $value );
509
- elseif ( '>=' == $operator ) :
510
- $match = ( $woocommerce->cart->cart_contents_weight >= $value );
511
- elseif ( '<=' == $operator ) :
512
- $match = ( $woocommerce->cart->cart_contents_weight <= $value );
513
- endif;
514
-
515
- return $match;
516
-
517
- }
518
-
519
-
520
- /* Match all product stock
521
- *
522
- * @param bool $match
523
- * @param string $operator
524
- * @param mixed $value
525
- * @return bool
526
  */
527
  public function wafs_match_condition_stock( $match, $operator, $value ) {
528
 
529
  global $woocommerce;
530
-
531
  if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
532
 
533
  foreach ( $woocommerce->cart->cart_contents as $product ) :
534
 
535
- if ( true == $product['data']->variation_has_stock ) :
536
  $stock[] = ( get_post_meta( $product['data']->variation_id, '_stock', true ) );
537
  else :
538
  $stock[] = ( get_post_meta( $product['product_id'], '_stock', true ) );
539
  endif;
540
 
541
  endforeach;
542
-
543
  $min_stock = min( $stock );
544
 
545
  if ( '==' == $operator ) :
@@ -551,33 +696,40 @@ class Wafs_Match_Conditions {
551
  elseif ( '<=' == $operator ) :
552
  $match = ( $min_stock <= $value );
553
  endif;
554
-
555
  return $match;
556
-
557
  }
558
 
559
 
560
- /* Match all product stock statusses
 
 
 
 
 
561
  *
562
- * @param bool $match
563
- * @param string $operator
564
- * @param mixed $value
565
- * @return bool
 
 
566
  */
567
  public function wafs_match_condition_stock_status( $match, $operator, $value ) {
568
 
569
  global $woocommerce;
570
 
571
  if ( ! isset( $woocommerce->cart ) ) return;
572
-
573
  if ( '==' == $operator ) :
574
-
575
  $match = true;
576
  foreach ( $woocommerce->cart->cart_contents as $product ) :
577
  if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value )
578
  $match = false;
579
  endforeach;
580
-
581
  elseif ( '!=' == $operator ) :
582
 
583
  $match = true;
@@ -585,55 +737,63 @@ class Wafs_Match_Conditions {
585
  if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value )
586
  $match = false;
587
  endforeach;
588
-
589
  endif;
590
-
591
  return $match;
592
-
593
- }
594
-
595
 
596
- /* Match category
 
 
 
 
 
 
 
597
  *
598
- * @param bool $match
599
- * @param string $operator
600
- * @param mixed $value
601
- * @return bool
 
 
 
 
602
  */
603
  public function wafs_match_condition_category( $match, $operator, $value ) {
604
 
605
  global $woocommerce;
606
 
607
  if ( ! isset( $woocommerce->cart ) ) return;
608
-
609
  $match = true;
610
-
611
  if ( '==' == $operator ) :
612
-
613
  foreach ( $woocommerce->cart->cart_contents as $product ) :
614
 
615
  if ( ! has_term( $value, 'product_cat', $product['product_id'] ) ) :
616
  $match = false;
617
  endif;
618
-
619
  endforeach;
620
-
621
  elseif ( '!=' == $operator ) :
622
-
623
  foreach ( $woocommerce->cart->cart_contents as $product ) :
624
-
625
- if ( has_term( $value, 'product_cat', $post->ID ) ) :
626
  $match = false;
627
  endif;
628
-
629
  endforeach;
630
-
631
  endif;
632
-
633
  return $match;
634
-
635
  }
636
-
637
  }
638
  new Wafs_Match_Conditions();
639
 
1
  <?php
2
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
  /**
4
+ * Class WAFS_Match_Conditions.
5
  *
6
+ * The WAFS Match Conditions class handles the matching rules for Free Shipping.
7
  *
8
+ * @class WAFS_Match_Conditions
9
+ * @author Jeroen Sormani
10
+ * @package WooCommerce Advanced Free Shipping
11
+ * @version 1.0.0
12
  */
13
+ class WAFS_Match_Conditions {
14
 
15
 
16
  /**
17
+ * Constructor.
18
+ *
19
+ * @since 1.0.0 */
20
  public function __construct() {
21
+
22
  global $woocommerce;
23
+
24
+ add_filter( 'wafs_match_condition_subtotal', array( $this, 'wafs_match_condition_subtotal' ), 10, 3 );
25
+ add_filter( 'wafs_match_condition_subtotal_ex_tax', array( $this, 'wafs_match_condition_subtotal_ex_tax' ), 10, 3 );
26
+ add_filter( 'wafs_match_condition_tax', array( $this, 'wafs_match_condition_tax' ), 10, 3 );
27
+ add_filter( 'wafs_match_condition_quantity', array( $this, 'wafs_match_condition_quantity' ), 10, 3 );
28
+ add_filter( 'wafs_match_condition_contains_product', array( $this, 'wafs_match_condition_contains_product' ), 10, 3 );
29
+ add_filter( 'wafs_match_condition_coupon', array( $this, 'wafs_match_condition_coupon' ), 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
+ * @global object $woocommerce WooCommerce object.
56
+ *
57
+ * @param bool $match Current match value.
58
+ * @param string $operator Operator selected by the user in the condition row.
59
+ * @param mixed $value Value given by the user in the condition row.
60
+ * @return BOOL Matching result, TRUE if results match, otherwise FALSE.
61
  */
62
  public function wafs_match_condition_subtotal( $match, $operator, $value ) {
63
 
64
  global $woocommerce;
65
 
66
  if ( ! isset( $woocommerce->cart ) ) return;
67
+
68
  if ( '==' == $operator ) :
69
  $match = ( $woocommerce->cart->subtotal == $value );
70
  elseif ( '!=' == $operator ) :
74
  elseif ( '<=' == $operator ) :
75
  $match = ( $woocommerce->cart->subtotal <= $value );
76
  endif;
77
+
78
  return $match;
79
+
80
  }
81
 
82
 
83
+ /**
84
+ * Subtotal excl. taxes.
85
+ *
86
+ * Match the condition value against the cart subtotal excl. taxes.
87
+ *
88
+ * @since 1.0.0
89
  *
90
+ * @global object $woocommerce WooCommerce object.
91
+ *
92
+ * @param bool $match Current match value.
93
+ * @param string $operator Operator selected by the user in the condition row.
94
+ * @param mixed $value Value given by the user in the condition row.
95
+ * @return BOOL Matching result, TRUE if results match, otherwise FALSE.
96
  */
97
  public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
98
 
99
  global $woocommerce;
100
+
101
  if ( ! isset( $woocommerce->cart ) ) return;
102
 
103
  if ( '==' == $operator ) :
109
  elseif ( '<=' == $operator ) :
110
  $match = ( $woocommerce->cart->subtotal_ex_tax <= $value );
111
  endif;
112
+
113
  return $match;
114
+
115
  }
 
116
 
117
+
118
+ /**
119
+ * Taxes.
120
+ *
121
+ * Match the condition value against the cart taxes.
122
+ *
123
+ * @since 1.0.0
124
  *
125
+ * @global object $woocommerce WooCommerce object.
126
+ *