WooCommerce Advanced Free Shipping - Version 1.0.5

Version Description

  • 14-12-2014 =

  • Fix - Hide other shipping doesn't save in rare cases

  • Improvement - Use of WC() singleton instead of $woocommerce global

  • Improvement - Add background color to overview table every other row

Download this release

Release Info

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

Code changes from version 1.0.4 to 1.0.5

includes/admin/settings/conditions/class-wafs-condition.php CHANGED
@@ -193,7 +193,9 @@ class WAFS_Condition {
193
 
194
  }
195
 
 
196
  }
 
197
  /**
198
  * Load condition keys dropdown.
199
  */
193
 
194
  }
195
 
196
+
197
  }
198
+
199
  /**
200
  * Load condition keys dropdown.
201
  */
includes/admin/settings/conditions/condition-conditions.php CHANGED
@@ -43,14 +43,12 @@ function wafs_condition_conditions( $id, $group = 0, $current_value = 'subtotal'
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
@@ -64,9 +62,8 @@ function wafs_condition_conditions( $id, $group = 0, $current_value = 'subtotal'
64
  ?></optgroup><?php
65
 
66
  endforeach;
67
- ?>
68
 
69
- </select>
70
 
71
  </span><?php
72
 
43
  );
44
 
45
  $conditions = apply_filters( 'wafs_conditions', $conditions );
 
46
 
47
+ ?><span class='wafs-condition-wrap wafs-condition-wrap-<?php echo $id; ?>'>
48
 
49
  <select class='wafs-condition' data-group='<?php echo $group; ?>' data-id='<?php echo $id; ?>'
50
+ name='_wafs_shipping_method_conditions[<?php echo $group; ?>][<?php echo $id; ?>][condition]'><?php
51
 
 
52
  foreach ( $conditions as $option_group => $values ) :
53
 
54
  ?><optgroup label='<?php echo $option_group; ?>'><?php
62
  ?></optgroup><?php
63
 
64
  endforeach;
 
65
 
66
+ ?></select>
67
 
68
  </span><?php
69
 
includes/admin/settings/conditions/condition-descriptions.php CHANGED
@@ -38,9 +38,9 @@ function wafs_condition_description( $condition ) {
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
 
38
 
39
  <img class='wafs_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' />
40
 
41
+ <div class='wafs_desc'><?php
42
+ echo $descriptions[ $condition ];
43
+ ?></div>
44
 
45
  </div>
46
 
includes/admin/settings/conditions/condition-values.php CHANGED
@@ -15,8 +15,6 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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
 
@@ -102,13 +100,13 @@ function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $curre
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;
@@ -120,7 +118,7 @@ function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $curre
120
  case 'country' :
121
 
122
  $values['field'] = 'select';
123
- $values['options'] = $woocommerce->countries->get_allowed_countries();
124
 
125
  break;
126
 
15
  */
16
  function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $current_value = '' ) {
17
 
 
 
18
  // Defaults
19
  $values = array( 'placeholder' => '', 'min' => '', 'max' => '', 'field' => 'text', 'options' => array() );
20
 
100
 
101
  $values['field'] = 'select';
102
 
103
+ foreach ( WC()->countries->states as $country => $states ) :
104
 
105
  if ( empty( $states ) ) continue; // Don't show country if it has no states
106
+ if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries
107
 
108
  foreach ( $states as $state_key => $state ) :
109
+ $country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state;
110
  endforeach;
111
 
112
  $values['options'] = $country_states;
118
  case 'country' :
119
 
120
  $values['field'] = 'select';
121
+ $values['options'] = WC()->countries->get_allowed_countries();
122
 
123
  break;
124
 
includes/admin/settings/meta-box-settings.php CHANGED
@@ -15,8 +15,8 @@ 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
 
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
 
includes/admin/views/conditions-table.php CHANGED
@@ -12,8 +12,8 @@
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> -->
@@ -28,14 +28,16 @@ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' =>
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' ); ?>'>
@@ -64,13 +66,13 @@ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' =>
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;'>
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> -->
28
  <th style='padding-left: 10px;'><?php _e( 'Condition groups', 'woocommerce-advanced-free-shipping' ); ?></th>
29
  </tr>
30
  </thead>
31
+ <tbody><?php
32
+
33
+ $i = 0;
34
  foreach ( $method_conditions as $method_condition ) :
35
 
36
  $method_details = get_post_meta( $method_condition->ID, '_wafs_shipping_method', true );
37
  $conditions = get_post_meta( $method_condition->ID, '_wafs_shipping_method_conditions', true );
38
+ $alt = ( $i++ ) % 2 == 0 ? 'alternate' : '';
39
 
40
+ ?><tr class='<?php echo $alt; ?>'>
41
  <td>
42
  <strong>
43
  <a href='<?php echo get_edit_post_link( $method_condition->ID ); ?>' class='row-title' title='<?php _e( 'Edit Method', 'woocommerce-advanced-free-shipping' ); ?>'>
66
  endforeach;
67
 
68
  if ( empty( $method_conditions ) ) :
69
+
70
+ ?><tr>
71
  <td colspan='2'><?php _e( 'There are no Free Shipping methods. Yet...', 'woocommerce-advanced-free-shipping' ); ?></td>
72
+ </tr><?php
73
+ endif;
74
 
75
+ ?></tbody>
76
  <tfoot>
77
  <tr>
78
  <th colspan='4' style='padding-left: 10px;'>
includes/class-wafs-ajax.php CHANGED
@@ -56,19 +56,17 @@ class WAFS_Ajax {
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
 
@@ -104,4 +102,3 @@ class WAFS_Ajax {
104
 
105
 
106
  }
107
- new WAFS_Ajax();
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><?php
63
+
64
  new WAFS_Condition( null, $_POST['group'] );
 
65
 
66
+ ?></div>
67
 
68
+ <p><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
69
 
 
70
  die();
71
  }
72
 
102
 
103
 
104
  }
 
includes/class-wafs-match-conditions.php CHANGED
@@ -20,29 +20,27 @@ class WAFS_Match_Conditions {
20
  */
21
  public function __construct() {
22
 
23
- global $woocommerce;
24
-
25
- add_filter( 'wafs_match_condition_subtotal', array( $this, 'wafs_match_condition_subtotal' ), 10, 3 );
26
- add_filter( 'wafs_match_condition_subtotal_ex_tax', array( $this, 'wafs_match_condition_subtotal_ex_tax' ), 10, 3 );
27
- add_filter( 'wafs_match_condition_tax', array( $this, 'wafs_match_condition_tax' ), 10, 3 );
28
- add_filter( 'wafs_match_condition_quantity', array( $this, 'wafs_match_condition_quantity' ), 10, 3 );
29
- add_filter( 'wafs_match_condition_contains_product', array( $this, 'wafs_match_condition_contains_product' ), 10, 3 );
30
- add_filter( 'wafs_match_condition_coupon', array( $this, 'wafs_match_condition_coupon' ), 10, 3 );
31
- add_filter( 'wafs_match_condition_weight', array( $this, 'wafs_match_condition_weight' ), 10, 3 );
32
- add_filter( 'wafs_match_condition_contains_shipping_class', array( $this, 'wafs_match_condition_contains_shipping_class' ), 10, 3 );
33
-
34
- add_filter( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 );
35
- add_filter( 'wafs_match_condition_city', array( $this, 'wafs_match_condition_city' ), 10, 3 );
36
- add_filter( 'wafs_match_condition_state', array( $this, 'wafs_match_condition_state' ), 10, 3 );
37
- add_filter( 'wafs_match_condition_country', array( $this, 'wafs_match_condition_country' ), 10, 3 );
38
- add_filter( 'wafs_match_condition_role', array( $this, 'wafs_match_condition_role' ), 10, 3 );
39
-
40
- add_filter( 'wafs_match_condition_width', array( $this, 'wafs_match_condition_width' ), 10, 3 );
41
- add_filter( 'wafs_match_condition_height', array( $this, 'wafs_match_condition_height' ), 10, 3 );
42
- add_filter( 'wafs_match_condition_length', array( $this, 'wafs_match_condition_length' ), 10, 3 );
43
- add_filter( 'wafs_match_condition_stock', array( $this, 'wafs_match_condition_stock' ), 10, 3 );
44
- add_filter( 'wafs_match_condition_stock_status', array( $this, 'wafs_match_condition_stock_status' ), 10, 3 );
45
- add_filter( 'wafs_match_condition_category', array( $this, 'wafs_match_condition_category' ), 10, 3 );
46
 
47
  }
48
 
@@ -54,8 +52,6 @@ class WAFS_Match_Conditions {
54
  *
55
  * @since 1.0.0
56
  *
57
- * @global object $woocommerce WooCommerce object.
58
- *
59
  * @param bool $match Current match value.
60
  * @param string $operator Operator selected by the user in the condition row.
61
  * @param mixed $value Value given by the user in the condition row.
@@ -63,18 +59,16 @@ class WAFS_Match_Conditions {
63
  */
64
  public function wafs_match_condition_subtotal( $match, $operator, $value ) {
65
 
66
- global $woocommerce;
67
-
68
- if ( ! isset( $woocommerce->cart ) ) return;
69
 
70
  if ( '==' == $operator ) :
71
- $match = ( $woocommerce->cart->subtotal == $value );
72
  elseif ( '!=' == $operator ) :
73
- $match = ( $woocommerce->cart->subtotal != $value );
74
  elseif ( '>=' == $operator ) :
75
- $match = ( $woocommerce->cart->subtotal >= $value );
76
  elseif ( '<=' == $operator ) :
77
- $match = ( $woocommerce->cart->subtotal <= $value );
78
  endif;
79
 
80
  return $match;
@@ -89,8 +83,6 @@ class WAFS_Match_Conditions {
89
  *
90
  * @since 1.0.0
91
  *
92
- * @global object $woocommerce WooCommerce object.
93
- *
94
  * @param bool $match Current match value.
95
  * @param string $operator Operator selected by the user in the condition row.
96
  * @param mixed $value Value given by the user in the condition row.
@@ -98,18 +90,16 @@ class WAFS_Match_Conditions {
98
  */
99
  public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
100
 
101
- global $woocommerce;
102
-
103
- if ( ! isset( $woocommerce->cart ) ) return;
104
 
105
  if ( '==' == $operator ) :
106
- $match = ( $woocommerce->cart->subtotal_ex_tax == $value );
107
  elseif ( '!=' == $operator ) :
108
- $match = ( $woocommerce->cart->subtotal_ex_tax != $value );
109
  elseif ( '>=' == $operator ) :
110
- $match = ( $woocommerce->cart->subtotal_ex_tax >= $value );
111
  elseif ( '<=' == $operator ) :
112
- $match = ( $woocommerce->cart->subtotal_ex_tax <= $value );
113
  endif;
114
 
115
  return $match;
@@ -124,8 +114,6 @@ class WAFS_Match_Conditions {
124
  *
125
  * @since 1.0.0
126
  *
127
- * @global object $woocommerce WooCommerce object.
128
- *
129
  * @param bool $match Current match value.
130
  * @param string $operator Operator selected by the user in the condition row.
131
  * @param mixed $value Value given by the user in the condition row.
@@ -133,11 +121,9 @@ class WAFS_Match_Conditions {
133
  */
134
  public function wafs_match_condition_tax( $match, $operator, $value ) {
135
 
136
- global $woocommerce;
137
 
138
- if ( ! isset( $woocommerce->cart ) ) return;
139
-
140
- $taxes = array_sum( (array) $woocommerce->cart->taxes );
141
 
142
  if ( '==' == $operator ) :
143
  $match = ( $taxes == $value );
@@ -162,8 +148,6 @@ class WAFS_Match_Conditions {
162
  *
163
  * @since 1.0.0
164
  *
165
- * @global object $woocommerce WooCommerce object.
166
- *
167
  * @param bool $match Current match value.
168
  * @param string $operator Operator selected by the user in the condition row.
169
  * @param mixed $value Value given by the user in the condition row.
@@ -171,18 +155,16 @@ class WAFS_Match_Conditions {
171
  */
172
  public function wafs_match_condition_quantity( $match, $operator, $value ) {
173
 
174
- global $woocommerce;
175
-
176
- if ( ! isset( $woocommerce->cart ) ) return;
177
 
178
  if ( '==' == $operator ) :
179
- $match = ( $woocommerce->cart->cart_contents_count == $value );
180
  elseif ( '!=' == $operator ) :
181
- $match = ( $woocommerce->cart->cart_contents_count != $value );
182
  elseif ( '>=' == $operator ) :
183
- $match = ( $woocommerce->cart->cart_contents_count >= $value );
184
  elseif ( '<=' == $operator ) :
185
- $match = ( $woocommerce->cart->cart_contents_count <= $value );
186
  endif;
187
 
188
  return $match;
@@ -197,8 +179,6 @@ class WAFS_Match_Conditions {
197
  *
198
  * @since 1.0.0
199
  *
200
- * @global object $woocommerce WooCommerce object.
201
- *
202
  * @param bool $match Current match value.
203
  * @param string $operator Operator selected by the user in the condition row.
204
  * @param mixed $value Value given by the user in the condition row.
@@ -206,11 +186,9 @@ class WAFS_Match_Conditions {
206
  */
207
  public function wafs_match_condition_contains_product( $match, $operator, $value ) {
208
 
209
- global $woocommerce;
210
-
211
- if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
212
 
213
- foreach ( $woocommerce->cart->cart_contents as $product ) :
214
  $product_ids[] = $product['product_id'];
215
  endforeach;
216
 
@@ -232,8 +210,6 @@ class WAFS_Match_Conditions {
232
  *
233
  * @since 1.0.0
234
  *
235
- * @global object $woocommerce WooCommerce object.
236
- *
237
  * @param bool $match Current match value.
238
  * @param string $operator Operator selected by the user in the condition row.
239
  * @param mixed $value Value given by the user in the condition row.
@@ -241,14 +217,12 @@ class WAFS_Match_Conditions {
241
  */
242
  public function wafs_match_condition_coupon( $match, $operator, $value ) {
243
 
244
- global $woocommerce;
245
-
246
- if ( ! isset( $woocommerce->cart ) ) return;
247
 
248
  if ( '==' == $operator ) :
249
- $match = ( in_array( $value, $woocommerce->cart->applied_coupons ) );
250
  elseif ( '!=' == $operator ) :
251
- $match = ( ! in_array( $value, $woocommerce->cart->applied_coupons ) );
252
  endif;
253
 
254
  return $match;
@@ -263,8 +237,6 @@ class WAFS_Match_Conditions {
263
  *
264
  * @since 1.0.0
265
  *
266
- * @global object $woocommerce WooCommerce object.
267
- *
268
  * @param bool $match Current match value.
269
  * @param string $operator Operator selected by the user in the condition row.
270
  * @param mixed $value Value given by the user in the condition row.
@@ -272,18 +244,16 @@ class WAFS_Match_Conditions {
272
  */
273
  public function wafs_match_condition_weight( $match, $operator, $value ) {
274
 
275
- global $woocommerce;
276
-
277
- if ( ! isset( $woocommerce->cart ) ) return;
278
 
279
  if ( '==' == $operator ) :
280
- $match = ( $woocommerce->cart->cart_contents_weight == $value );
281
  elseif ( '!=' == $operator ) :
282
- $match = ( $woocommerce->cart->cart_contents_weight != $value );
283
  elseif ( '>=' == $operator ) :
284
- $match = ( $woocommerce->cart->cart_contents_weight >= $value );
285
  elseif ( '<=' == $operator ) :
286
- $match = ( $woocommerce->cart->cart_contents_weight <= $value );
287
  endif;
288
 
289
  return $match;
@@ -304,16 +274,14 @@ class WAFS_Match_Conditions {
304
  * @return BOOL Matching result, TRUE if results match, otherwise FALSE. */
305
  public function wafs_match_condition_contains_shipping_class( $match, $operator, $value ) {
306
 
307
- global $woocommerce;
308
-
309
- if ( ! isset( $woocommerce->cart ) ) return;
310
 
311
  if ( $operator == '!=' ) :
312
  // True until proven false
313
  $match = true;
314
  endif;
315
 
316
- foreach ( $woocommerce->cart->cart_contents as $product ) :
317
 
318
  $product = get_product( $product['product_id'] );
319
 
@@ -346,8 +314,6 @@ class WAFS_Match_Conditions {
346
  *
347
  * @since 1.0.2; $value may contain single or comma (,) separated zipcodes.
348
  *
349
- * @global object $woocommerce WooCommerce object.
350
- *
351
  * @param bool $match Current match value.
352
  * @param string $operator Operator selected by the user in the condition row.
353
  * @param mixed $value Value given by the user in the condition row.
@@ -355,30 +321,28 @@ class WAFS_Match_Conditions {
355
  */
356
  public function wafs_match_condition_zipcode( $match, $operator, $value ) {
357
 
358
- global $woocommerce;
359
-
360
- if ( ! isset( $woocommerce->customer ) ) return;
361
 
362
  if ( '==' == $operator ) :
363
 
364
  if ( preg_match( '/\, ?/', $value ) ) :
365
- $match = ( in_array( (int) $woocommerce->customer->get_shipping_postcode(), array_map( 'intval', explode( ',', $value ) ) ) );
366
  else :
367
- $match = ( (int) $woocommerce->customer->get_shipping_postcode() == (int) $value );
368
  endif;
369
 
370
  elseif ( '!=' == $operator ) :
371
 
372
  if ( preg_match( '/\, ?/', $value ) ) :
373
- $match = ( ! in_array( (int) $woocommerce->customer->get_shipping_postcode(), array_map( 'intval', explode( ',', $value ) ) ) );
374
  else :
375
- $match = ( (int) $woocommerce->customer->get_shipping_postcode() != (int) $value );
376
  endif;
377
 
378
  elseif ( '>=' == $operator ) :
379
- $match = ( (int) $woocommerce->customer->get_shipping_postcode() >= (int) $value );
380
  elseif ( '<=' == $operator ) :
381
- $match = ( (int) $woocommerce->customer->get_shipping_postcode() <= (int) $value );
382
  endif;
383
 
384
  return $match;
@@ -393,8 +357,6 @@ class WAFS_Match_Conditions {
393
  *
394
  * @since 1.0.0
395
  *
396
- * @global object $woocommerce WooCommerce object.
397
- *
398
  * @param bool $match Current match value.
399
  * @param string $operator Operator selected by the user in the condition row.
400
  * @param mixed $value Value given by the user in the condition row.
@@ -402,14 +364,12 @@ class WAFS_Match_Conditions {
402
  */
403
  public function wafs_match_condition_city( $match, $operator, $value ) {
404
 
405
- global $woocommerce;
406
-
407
- if ( ! isset( $woocommerce->customer ) ) return;
408
 
409
  if ( '==' == $operator ) :
410
- $match = ( preg_match( "/^$value$/i", $woocommerce->customer->get_shipping_city() ) );
411
  elseif ( '!=' == $operator ) :
412
- $match = ( ! preg_match( "/^$value$/i", $woocommerce->customer->get_shipping_city() ) );
413
  endif;
414
 
415
  return $match;
@@ -424,8 +384,6 @@ class WAFS_Match_Conditions {
424
  *
425
  * @since 1.0.0
426
  *
427
- * @global object $woocommerce WooCommerce object.
428
- *
429
  * @param bool $match Current match value.
430
  * @param string $operator Operator selected by the user in the condition row.
431
  * @param mixed $value Value given by the user in the condition row.
@@ -433,11 +391,9 @@ class WAFS_Match_Conditions {
433
  True if this condition matches, false if condition doesn't match. */
434
  public function wafs_match_condition_state( $match, $operator, $value ) {
435
 
436
- global $woocommerce;
437
-
438
- if ( ! isset( $woocommerce->customer ) ) return;
439
 
440
- $state = $woocommerce->customer->get_shipping_country() . '_' . $woocommerce->customer->get_shipping_state();
441
 
442
  if ( '==' == $operator ) :
443
  $match = ( $state == $value );
@@ -457,8 +413,6 @@ class WAFS_Match_Conditions {
457
  *
458
  * @since 1.0.0
459
  *
460
- * @global object $woocommerce WooCommerce object.
461
- *
462
  * @param bool $match Current match value.
463
  * @param string $operator Operator selected by the user in the condition row.
464
  * @param mixed $value Value given by the user in the condition row.
@@ -466,14 +420,12 @@ class WAFS_Match_Conditions {
466
  */
467
  public function wafs_match_condition_country( $match, $operator, $value ) {
468
 
469
- global $woocommerce;
470
-
471
- if ( ! isset( $woocommerce->customer ) ) return;
472
 
473
  if ( '==' == $operator ) :
474
- $match = ( preg_match( "/^$value$/i", $woocommerce->customer->get_shipping_country() ) );
475
  elseif ( '!=' == $operator ) :
476
- $match = ( ! preg_match( "/^$value$/i", $woocommerce->customer->get_shipping_country() ) );
477
  endif;
478
 
479
  return $match;
@@ -487,8 +439,6 @@ class WAFS_Match_Conditions {
487
  * Match the condition value against the users role.
488
  *
489
  * @since 1.0.0
490
- *
491
- * @global object $woocommerce WooCommerce object.
492
  * @global object $current_user Current user object for capabilities.
493
  *
494
  * @param bool $match Current match value.
@@ -498,7 +448,7 @@ class WAFS_Match_Conditions {
498
  */
499
  public function wafs_match_condition_role( $match, $operator, $value ) {
500
 
501
- global $woocommerce, $current_user;
502
 
503
  if ( '==' == $operator ) :
504
  $match = ( array_key_exists( $value, $current_user->caps ) );
@@ -523,8 +473,6 @@ class WAFS_Match_Conditions {
523
  *
524
  * @since 1.0.0
525
  *
526
- * @global object $woocommerce WooCommerce object.
527
- *
528
  * @param bool $match Current match value.
529
  * @param string $operator Operator selected by the user in the condition row.
530
  * @param mixed $value Value given by the user in the condition row.
@@ -532,11 +480,9 @@ class WAFS_Match_Conditions {
532
  */
533
  public function wafs_match_condition_width( $match, $operator, $value ) {
534
 
535
- global $woocommerce;
536
-
537
- if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
538
 
539
- foreach ( $woocommerce->cart->cart_contents as $product ) :
540
 
541
  if ( true == $product['data']->variation_has_width ) :
542
  $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) );
@@ -570,8 +516,6 @@ class WAFS_Match_Conditions {
570
  *
571
  * @since 1.0.0
572
  *
573
- * @global object $woocommerce WooCommerce object.
574
- *
575
  * @param bool $match Current match value.
576
  * @param string $operator Operator selected by the user in the condition row.
577
  * @param mixed $value Value given by the user in the condition row.
@@ -579,11 +523,9 @@ class WAFS_Match_Conditions {
579
  */
580
  public function wafs_match_condition_height( $match, $operator, $value ) {
581
 
582
- global $woocommerce;
583
-
584
- if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
585
 
586
- foreach ( $woocommerce->cart->cart_contents as $product ) :
587
 
588
  if ( true == $product['data']->variation_has_height ) :
589
  $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) );
@@ -617,8 +559,6 @@ class WAFS_Match_Conditions {
617
  *
618
  * @since 1.0.0
619
  *
620
- * @global object $woocommerce WooCommerce object.
621
- *
622
  * @param bool $match Current match value.
623
  * @param string $operator Operator selected by the user in the condition row.
624
  * @param mixed $value Value given by the user in the condition row.
@@ -626,11 +566,9 @@ class WAFS_Match_Conditions {
626
  */
627
  public function wafs_match_condition_length( $match, $operator, $value ) {
628
 
629
- global $woocommerce;
630
-
631
- if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
632
 
633
- foreach ( $woocommerce->cart->cart_contents as $product ) :
634
 
635
  if ( true == $product['data']->variation_has_length ) :
636
  $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) );
@@ -664,8 +602,6 @@ class WAFS_Match_Conditions {
664
  *
665
  * @since 1.0.0
666
  *
667
- * @global object $woocommerce WooCommerce object.
668
- *
669
  * @param bool $match Current match value.
670
  * @param string $operator Operator selected by the user in the condition row.
671
  * @param mixed $value Value given by the user in the condition row.
@@ -673,11 +609,9 @@ class WAFS_Match_Conditions {
673
  */
674
  public function wafs_match_condition_stock( $match, $operator, $value ) {
675
 
676
- global $woocommerce;
677
 
678
- if ( ! isset( $woocommerce->cart ) || empty( $woocommerce->cart->cart_contents ) ) return;
679
-
680
- foreach ( $woocommerce->cart->cart_contents as $product ) :
681
 
682
  if ( true == $product['data']->variation_has_stock ) :
683
  $stock[] = ( get_post_meta( $product['data']->variation_id, '_stock', true ) );
@@ -711,8 +645,6 @@ class WAFS_Match_Conditions {
711
  *
712
  * @since 1.0.0
713
  *
714
- * @global object $woocommerce WooCommerce object.
715
- *
716
  * @param bool $match Current match value.
717
  * @param string $operator Operator selected by the user in the condition row.
718
  * @param mixed $value Value given by the user in the condition row.
@@ -720,14 +652,12 @@ class WAFS_Match_Conditions {
720
  */
721
  public function wafs_match_condition_stock_status( $match, $operator, $value ) {
722
 
723
- global $woocommerce;
724
-
725
- if ( ! isset( $woocommerce->cart ) ) return;
726
 
727
  if ( '==' == $operator ) :
728
 
729
  $match = true;
730
- foreach ( $woocommerce->cart->cart_contents as $product ) :
731
  if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value )
732
  $match = false;
733
  endforeach;
@@ -735,7 +665,7 @@ class WAFS_Match_Conditions {
735
  elseif ( '!=' == $operator ) :
736
 
737
  $match = true;
738
- foreach ( $woocommerce->cart->cart_contents as $product ) :
739
  if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value )
740
  $match = false;
741
  endforeach;
@@ -755,8 +685,6 @@ class WAFS_Match_Conditions {
755
  *
756
  * @since 1.0.0
757
  *
758
- * @global object $woocommerce WooCommerce object.
759
- *
760
  * @param bool $match Current match value.
761
  * @param string $operator Operator selected by the user in the condition row.
762
  * @param mixed $value Value given by the user in the condition row.
@@ -764,15 +692,13 @@ class WAFS_Match_Conditions {
764
  */
765
  public function wafs_match_condition_category( $match, $operator, $value ) {
766
 
767
- global $woocommerce;
768
-
769
- if ( ! isset( $woocommerce->cart ) ) return;
770
 
771
  $match = true;
772
 
773
  if ( '==' == $operator ) :
774
 
775
- foreach ( $woocommerce->cart->cart_contents as $product ) :
776
 
777
  if ( ! has_term( $value, 'product_cat', $product['product_id'] ) ) :
778
  $match = false;
@@ -782,7 +708,7 @@ class WAFS_Match_Conditions {
782
 
783
  elseif ( '!=' == $operator ) :
784
 
785
- foreach ( $woocommerce->cart->cart_contents as $product ) :
786
 
787
  if ( has_term( $value, 'product_cat', $product['product_id'] ) ) :
788
  $match = false;
@@ -797,6 +723,3 @@ class WAFS_Match_Conditions {
797
  }
798
 
799
  }
800
- new Wafs_Match_Conditions();
801
-
802
- ?>
20
  */
21
  public function __construct() {
22
 
23
+ add_filter( 'wafs_match_condition_subtotal', array( $this, 'wafs_match_condition_subtotal' ), 10, 3 );
24
+ add_filter( 'wafs_match_condition_subtotal_ex_tax', array( $this, 'wafs_match_condition_subtotal_ex_tax' ), 10, 3 );
25
+ add_filter( 'wafs_match_condition_tax', array( $this, 'wafs_match_condition_tax' ), 10, 3 );
26
+ add_filter( 'wafs_match_condition_quantity', array( $this, 'wafs_match_condition_quantity' ), 10, 3 );
27
+ add_filter( 'wafs_match_condition_contains_product', array( $this, 'wafs_match_condition_contains_product' ), 10, 3 );
28
+ add_filter( 'wafs_match_condition_coupon', array( $this, 'wafs_match_condition_coupon' ), 10, 3 );
29
+ add_filter( 'wafs_match_condition_weight', array( $this, 'wafs_match_condition_weight' ), 10, 3 );
30
+ add_filter( 'wafs_match_condition_contains_shipping_class', array( $this, 'wafs_match_condition_contains_shipping_class' ), 10, 3 );
31
+
32
+ add_filter( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 );
33
+ add_filter( 'wafs_match_condition_city', array( $this, 'wafs_match_condition_city' ), 10, 3 );
34
+ add_filter( 'wafs_match_condition_state', array( $this, 'wafs_match_condition_state' ), 10, 3 );
35
+ add_filter( 'wafs_match_condition_country', array( $this, 'wafs_match_condition_country' ), 10, 3 );
36
+ add_filter( 'wafs_match_condition_role', array( $this, 'wafs_match_condition_role' ), 10, 3 );
37
+
38
+ add_filter( 'wafs_match_condition_width', array( $this, 'wafs_match_condition_width' ), 10, 3 );
39
+ add_filter( 'wafs_match_condition_height', array( $this, 'wafs_match_condition_height' ), 10, 3 );
40
+ add_filter( 'wafs_match_condition_length', array( $this, 'wafs_match_condition_length' ), 10, 3 );
41
+ add_filter( 'wafs_match_condition_stock', array( $this, 'wafs_match_condition_stock' ), 10, 3 );
42
+ add_filter( 'wafs_match_condition_stock_status', array( $this, 'wafs_match_condition_stock_status' ), 10, 3 );
43
+ add_filter( 'wafs_match_condition_category', array( $this, 'wafs_match_condition_category' ), 10, 3 );
 
 
44
 
45
  }
46
 
52
  *
53
  * @since 1.0.0
54
  *
 
 
55
  * @param bool $match Current match value.
56
  * @param string $operator Operator selected by the user in the condition row.
57
  * @param mixed $value Value given by the user in the condition row.
59
  */
60
  public function wafs_match_condition_subtotal( $match, $operator, $value ) {
61
 
62
+ if ( ! isset( WC()->cart ) ) return;
 
 
63
 
64
  if ( '==' == $operator ) :
65
+ $match = ( WC()->cart->subtotal == $value );
66
  elseif ( '!=' == $operator ) :
67
+ $match = ( WC()->cart->subtotal != $value );
68
  elseif ( '>=' == $operator ) :
69
+ $match = ( WC()->cart->subtotal >= $value );
70
  elseif ( '<=' == $operator ) :
71
+ $match = ( WC()->cart->subtotal <= $value );
72
  endif;
73
 
74
  return $match;
83
  *
84
  * @since 1.0.0
85
  *
 
 
86
  * @param bool $match Current match value.
87
  * @param string $operator Operator selected by the user in the condition row.
88
  * @param mixed $value Value given by the user in the condition row.
90
  */
91
  public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
92
 
93
+ if ( ! isset( WC()->cart ) ) return;
 
 
94
 
95
  if ( '==' == $operator ) :
96
+ $match = ( WC()->cart->subtotal_ex_tax == $value );
97
  elseif ( '!=' == $operator ) :
98
+ $match = ( WC()->cart->subtotal_ex_tax != $value );
99
  elseif ( '>=' == $operator ) :
100
+ $match = ( WC()->cart->subtotal_ex_tax >= $value );
101
  elseif ( '<=' == $operator ) :
102
+ $match = ( WC()->cart->subtotal_ex_tax <= $value );
103
  endif;
104
 
105
  return $match;
114
  *
115
  * @since 1.0.0
116
  *
 
 
117
  * @param bool $match Current match value.
118
  * @param string $operator Operator selected by the user in the condition row.
119
  * @param mixed $value Value given by the user in the condition row.
121
  */
122
  public function wafs_match_condition_tax( $match, $operator, $value ) {
123
 
124
+ if ( ! isset( WC()->cart ) ) return;
125
 
126
+ $taxes = array_sum( (array) WC()->cart->taxes );
 
 
127
 
128
  if ( '==' == $operator ) :
129
  $match = ( $taxes == $value );
148
  *
149
  * @since 1.0.0
150
  *
 
 
151
  * @param bool $match Current match value.
152
  * @param string $operator Operator selected by the user in the condition row.
153
  * @param mixed $value Value given by the user in the condition row.
155
  */
156
  public function wafs_match_condition_quantity( $match, $operator, $value ) {
157
 
158
+ if ( ! isset( WC()->cart ) ) return;
 
 
159
 
160
  if ( '==' == $operator ) :
161
+ $match = ( WC()->cart->cart_contents_count == $value );
162
  elseif ( '!=' == $operator ) :
163
+ $match = ( WC()->cart->cart_contents_count != $value );
164
  elseif ( '>=' == $operator ) :
165
+ $match = ( WC()->cart->cart_contents_count >= $value );
166
  elseif ( '<=' == $operator ) :
167
+ $match = ( WC()->cart->cart_contents_count <= $value );
168
  endif;
169
 
170
  return $match;
179
  *
180
  * @since 1.0.0
181
  *
 
 
182
  * @param bool $match Current match value.
183
  * @param string $operator Operator selected by the user in the condition row.
184
  * @param mixed $value Value given by the user in the condition row.
186
  */
187
  public function wafs_match_condition_contains_product( $match, $operator, $value ) {
188
 
189
+ if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return;
 
 
190
 
191
+ foreach ( WC()->cart->cart_contents as $product ) :
192
  $product_ids[] = $product['product_id'];
193
  endforeach;
194
 
210
  *
211
  * @since 1.0.0
212
  *
 
 
213
  * @param bool $match Current match value.
214
  * @param string $operator Operator selected by the user in the condition row.
215
  * @param mixed $value Value given by the user in the condition row.
217
  */
218
  public function wafs_match_condition_coupon( $match, $operator, $value ) {
219
 
220
+ if ( ! isset( WC()->cart ) ) return;
 
 
221
 
222
  if ( '==' == $operator ) :
223
+ $match = ( in_array( $value, WC()->cart->applied_coupons ) );
224
  elseif ( '!=' == $operator ) :
225
+ $match = ( ! in_array( $value, WC()->cart->applied_coupons ) );
226
  endif;
227
 
228
  return $match;
237
  *
238
  * @since 1.0.0
239
  *
 
 
240
  * @param bool $match Current match value.
241
  * @param string $operator Operator selected by the user in the condition row.
242
  * @param mixed $value Value given by the user in the condition row.
244
  */
245
  public function wafs_match_condition_weight( $match, $operator, $value ) {
246
 
247
+ if ( ! isset( WC()->cart ) ) return;
 
 
248
 
249
  if ( '==' == $operator ) :
250
+ $match = ( WC()->cart->cart_contents_weight == $value );
251
  elseif ( '!=' == $operator ) :
252
+ $match = ( WC()->cart->cart_contents_weight != $value );
253
  elseif ( '>=' == $operator ) :
254
+ $match = ( WC()->cart->cart_contents_weight >= $value );
255
  elseif ( '<=' == $operator ) :
256
+ $match = ( WC()->cart->cart_contents_weight <= $value );
257
  endif;
258
 
259
  return $match;
274
  * @return BOOL Matching result, TRUE if results match, otherwise FALSE. */
275
  public function wafs_match_condition_contains_shipping_class( $match, $operator, $value ) {
276
 
277
+ if ( ! isset( WC()->cart ) ) return;
 
 
278
 
279
  if ( $operator == '!=' ) :
280
  // True until proven false
281
  $match = true;
282
  endif;
283
 
284
+ foreach ( WC()->cart->cart_contents as $product ) :
285
 
286
  $product = get_product( $product['product_id'] );
287
 
314
  *
315
  * @since 1.0.2; $value may contain single or comma (,) separated zipcodes.
316
  *
 
 
317
  * @param bool $match Current match value.
318
  * @param string $operator Operator selected by the user in the condition row.
319
  * @param mixed $value Value given by the user in the condition row.
321
  */
322
  public function wafs_match_condition_zipcode( $match, $operator, $value ) {
323
 
324
+ if ( ! isset( WC()->customer ) ) return;
 
 
325
 
326
  if ( '==' == $operator ) :
327
 
328
  if ( preg_match( '/\, ?/', $value ) ) :
329
+ $match = ( in_array( (int) WC()->customer->get_shipping_postcode(), array_map( 'intval', explode( ',', $value ) ) ) );
330
  else :
331
+ $match = ( (int) WC()->customer->get_shipping_postcode() == (int) $value );
332
  endif;
333
 
334
  elseif ( '!=' == $operator ) :
335
 
336
  if ( preg_match( '/\, ?/', $value ) ) :
337
+ $match = ( ! in_array( (int) WC()->customer->get_shipping_postcode(), array_map( 'intval', explode( ',', $value ) ) ) );
338
  else :
339
+ $match = ( (int) WC()->customer->get_shipping_postcode() != (int) $value );
340
  endif;
341
 
342
  elseif ( '>=' == $operator ) :
343
+ $match = ( (int) WC()->customer->get_shipping_postcode() >= (int) $value );
344
  elseif ( '<=' == $operator ) :
345
+ $match = ( (int) WC()->customer->get_shipping_postcode() <= (int) $value );
346
  endif;
347
 
348
  return $match;
357
  *
358
  * @since 1.0.0
359
  *
 
 
360
  * @param bool $match Current match value.
361
  * @param string $operator Operator selected by the user in the condition row.
362
  * @param mixed $value Value given by the user in the condition row.
364
  */
365
  public function wafs_match_condition_city( $match, $operator, $value ) {
366
 
367
+ if ( ! isset( WC()->customer ) ) return;
 
 
368
 
369
  if ( '==' == $operator ) :
370
+ $match = ( preg_match( "/^$value$/i", WC()->customer->get_shipping_city() ) );
371
  elseif ( '!=' == $operator ) :
372
+ $match = ( ! preg_match( "/^$value$/i", WC()->customer->get_shipping_city() ) );
373
  endif;
374
 
375
  return $match;
384
  *
385
  * @since 1.0.0
386
  *
 
 
387
  * @param bool $match Current match value.
388
  * @param string $operator Operator selected by the user in the condition row.
389
  * @param mixed $value Value given by the user in the condition row.
391
  True if this condition matches, false if condition doesn't match. */
392
  public function wafs_match_condition_state( $match, $operator, $value ) {
393
 
394
+ if ( ! isset( WC()->customer ) ) return;
 
 
395
 
396
+ $state = WC()->customer->get_shipping_country() . '_' . WC()->customer->get_shipping_state();
397
 
398
  if ( '==' == $operator ) :
399
  $match = ( $state == $value );
413
  *
414
  * @since 1.0.0
415
  *
 
 
416
  * @param bool $match Current match value.
417
  * @param string $operator Operator selected by the user in the condition row.
418
  * @param mixed $value Value given by the user in the condition row.
420
  */
421
  public function wafs_match_condition_country( $match, $operator, $value ) {
422
 
423
+ if ( ! isset( WC()->customer ) ) return;
 
 
424
 
425
  if ( '==' == $operator ) :
426
+ $match = ( preg_match( "/^$value$/i", WC()->customer->get_shipping_country() ) );
427
  elseif ( '!=' == $operator ) :
428
+ $match = ( ! preg_match( "/^$value$/i", WC()->customer->get_shipping_country() ) );
429
  endif;
430
 
431
  return $match;
439
  * Match the condition value against the users role.
440
  *
441
  * @since 1.0.0
 
 
442
  * @global object $current_user Current user object for capabilities.
443
  *
444
  * @param bool $match Current match value.
448
  */
449
  public function wafs_match_condition_role( $match, $operator, $value ) {
450
 
451
+ global $current_user;
452
 
453
  if ( '==' == $operator ) :
454
  $match = ( array_key_exists( $value, $current_user->caps ) );
473
  *
474
  * @since 1.0.0
475
  *
 
 
476
  * @param bool $match Current match value.
477
  * @param string $operator Operator selected by the user in the condition row.
478
  * @param mixed $value Value given by the user in the condition row.
480
  */
481
  public function wafs_match_condition_width( $match, $operator, $value ) {
482
 
483
+ if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return;
 
 
484
 
485
+ foreach ( WC()->cart->cart_contents as $product ) :
486
 
487
  if ( true == $product['data']->variation_has_width ) :
488
  $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) );
516
  *
517
  * @since 1.0.0
518
  *
 
 
519
  * @param bool $match Current match value.
520
  * @param string $operator Operator selected by the user in the condition row.
521
  * @param mixed $value Value given by the user in the condition row.
523
  */
524
  public function wafs_match_condition_height( $match, $operator, $value ) {
525
 
526
+ if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return;
 
 
527
 
528
+ foreach ( WC()->cart->cart_contents as $product ) :
529
 
530
  if ( true == $product['data']->variation_has_height ) :
531
  $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) );
559
  *
560
  * @since 1.0.0
561
  *
 
 
562
  * @param bool $match Current match value.
563
  * @param string $operator Operator selected by the user in the condition row.
564
  * @param mixed $value Value given by the user in the condition row.
566
  */
567
  public function wafs_match_condition_length( $match, $operator, $value ) {
568
 
569
+ if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return;
 
 
570
 
571
+ foreach ( WC()->cart->cart_contents as $product ) :
572
 
573
  if ( true == $product['data']->variation_has_length ) :
574
  $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) );
602
  *
603
  * @since 1.0.0
604
  *
 
 
605
  * @param bool $match Current match value.
606
  * @param string $operator Operator selected by the user in the condition row.
607
  * @param mixed $value Value given by the user in the condition row.
609
  */
610
  public function wafs_match_condition_stock( $match, $operator, $value ) {
611
 
612
+ if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return;
613
 
614
+ foreach ( WC()->cart->cart_contents as $product ) :
 
 
615
 
616
  if ( true == $product['data']->variation_has_stock ) :
617
  $stock[] = ( get_post_meta( $product['data']->variation_id, '_stock', true ) );
645
  *
646
  * @since 1.0.0
647
  *
 
 
648
  * @param bool $match Current match value.
649
  * @param string $operator Operator selected by the user in the condition row.
650
  * @param mixed $value Value given by the user in the condition row.
652
  */
653
  public function wafs_match_condition_stock_status( $match, $operator, $value ) {
654
 
655
+ if ( ! isset( WC()->cart ) ) return;
 
 
656
 
657
  if ( '==' == $operator ) :
658
 
659
  $match = true;
660
+ foreach ( WC()->cart->cart_contents as $product ) :
661
  if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value )
662
  $match = false;
663
  endforeach;
665
  elseif ( '!=' == $operator ) :
666
 
667
  $match = true;
668
+ foreach ( WC()->cart->cart_contents as $product ) :
669
  if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value )
670
  $match = false;
671
  endforeach;
685
  *
686
  * @since 1.0.0
687
  *
 
 
688
  * @param bool $match Current match value.
689
  * @param string $operator Operator selected by the user in the condition row.
690
  * @param mixed $value Value given by the user in the condition row.
692
  */
693
  public function wafs_match_condition_category( $match, $operator, $value ) {
694
 
695
+ if ( ! isset( WC()->cart ) ) return;
 
 
696
 
697
  $match = true;
698
 
699
  if ( '==' == $operator ) :
700
 
701
+ foreach ( WC()->cart->cart_contents as $product ) :
702
 
703
  if ( ! has_term( $value, 'product_cat', $product['product_id'] ) ) :
704
  $match = false;
708
 
709
  elseif ( '!=' == $operator ) :
710
 
711
+ foreach ( WC()->cart->cart_contents as $product ) :
712
 
713
  if ( has_term( $value, 'product_cat', $product['product_id'] ) ) :
714
  $match = false;
723
  }
724
 
725
  }
 
 
 
includes/class-wafs-method.php CHANGED
@@ -39,14 +39,13 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
39
  $this->init_settings();
40
 
41
  $this->enabled = $this->get_option( 'enabled' );
42
- $this->hide_shipping = $this->get_option( 'hide_other_shipping_when_available' );
43
 
44
  // Save settings in admin if you have any defined
45
  add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
46
 
47
  // Hide shipping methods
48
- global $woocommerce;
49
- if ( version_compare( $woocommerce->version, '2.1', '<' ) ) :
50
  add_filter( 'woocommerce_available_shipping_methods', array( $this, 'hide_all_shipping_when_free_is_available' ) );
51
  else :
52
  add_filter( 'woocommerce_package_rates', array( $this, 'hide_all_shipping_when_free_is_available' ) );
@@ -143,7 +142,7 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
143
  'label' => __( 'Enable Advanced Free Shipping', 'woocommerce-advanced-free-shipping' ),
144
  'default' => 'yes'
145
  ),
146
- 'hide_other_shipping_when_available' => array(
147
  'title' => __( 'Hide other shipping', 'woocommerce-advanced-free-shipping' ),
148
  'type' => 'checkbox',
149
  'label' => __( 'Hide other shipping methods when free shipping is available', 'woocommerce-advanced-free-shipping' ),
@@ -258,4 +257,3 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
258
 
259
 
260
  }
261
- $wafs_free_shipping_method = new Wafs_Free_Shipping_Method();
39
  $this->init_settings();
40
 
41
  $this->enabled = $this->get_option( 'enabled' );
42
+ $this->hide_shipping = $this->get_option( 'hide_other_shipping' );
43
 
44
  // Save settings in admin if you have any defined
45
  add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
46
 
47
  // Hide shipping methods
48
+ if ( version_compare( WC()->version, '2.1', '<' ) ) :
 
49
  add_filter( 'woocommerce_available_shipping_methods', array( $this, 'hide_all_shipping_when_free_is_available' ) );
50
  else :
51
  add_filter( 'woocommerce_package_rates', array( $this, 'hide_all_shipping_when_free_is_available' ) );
142
  'label' => __( 'Enable Advanced Free Shipping', 'woocommerce-advanced-free-shipping' ),
143
  'default' => 'yes'
144
  ),
145
+ 'hide_other_shipping' => array(
146
  'title' => __( 'Hide other shipping', 'woocommerce-advanced-free-shipping' ),
147
  'type' => 'checkbox',
148
  'label' => __( 'Hide other shipping methods when free shipping is available', 'woocommerce-advanced-free-shipping' ),
257
 
258
 
259
  }
 
includes/class-wafs-post-type.php CHANGED
@@ -20,18 +20,19 @@ class WAFS_post_type {
20
  */
21
  public function __construct() {
22
 
23
- $this->wafs_register_post_type();
 
24
 
25
- // Add/save meta boxes
26
- add_action( 'add_meta_boxes', array( $this, 'wafs_post_type_meta_box' ) );
27
- add_action( 'save_post', array( $this, 'wafs_save_meta' ) );
28
- add_action( 'save_post', array( $this, 'wafs_save_condition_meta' ) );
29
 
30
- // Edit user messages
31
- add_filter( 'post_updated_messages', array( $this, 'wafs_custom_post_type_messages' ) );
32
 
33
- // Redirect after delete
34
- add_action('load-edit.php', array( $this, 'wafs_redirect_after_trash' ) );
35
 
36
  }
37
 
@@ -46,16 +47,16 @@ class WAFS_post_type {
46
  public function wafs_register_post_type() {
47
 
48
  $labels = array(
49
- 'name' => __( 'Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
50
  'singular_name' => __( 'Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
51
- 'add_new' => __( 'Add New', 'woocommerce-advanced-free-shipping' ),
52
- 'add_new_item' => __( 'Add New Advanced Free Shipping method' , 'woocommerce-advanced-free-shipping' ),
53
- 'edit_item' => __( 'Edit Advanced Free Shipping method' , 'woocommerce-advanced-free-shipping' ),
54
- 'new_item' => __( 'New Advanced Free Shipping method' , 'woocommerce-advanced-free-shipping' ),
55
- 'view_item' => __( 'View Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
56
- 'search_items' => __( 'Search Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
57
- 'not_found' => __( 'No Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
58
- 'not_found_in_trash' => __( 'No Advanced Free Shipping methods found in Trash', 'woocommerce-advanced-free-shipping' ),
59
  );
60
 
61
  register_post_type( 'wafs', array(
@@ -184,19 +185,23 @@ class WAFS_post_type {
184
  */
185
  public function wafs_save_condition_meta( $post_id ) {
186
 
187
- if ( ! isset( $_POST['wafs_conditions_meta_box_nonce'] ) )
188
  return $post_id;
 
189
 
190
  $nonce = $_POST['wafs_conditions_meta_box_nonce'];
191
 
192
- if ( ! wp_verify_nonce( $nonce, 'wafs_conditions_meta_box' ) )
193
  return $post_id;
 
194
 
195
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
196
  return $post_id;
 
197
 
198
- if ( ! current_user_can( 'manage_woocommerce' ) )
199
  return $post_id;
 
200
 
201
  $shipping_method_conditions = $_POST['_wafs_shipping_method_conditions'];
202
 
@@ -214,19 +219,23 @@ class WAFS_post_type {
214
  */
215
  public function wafs_save_meta( $post_id ) {
216
 
217
- if ( !isset( $_POST['wafs_settings_meta_box_nonce'] ) )
218
  return $post_id;
 
219
 
220
  $nonce = $_POST['wafs_settings_meta_box_nonce'];
221
 
222
- if ( ! wp_verify_nonce( $nonce, 'wafs_settings_meta_box' ) )
223
  return $post_id;
 
224
 
225
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
226
  return $post_id;
 
227
 
228
- if ( ! current_user_can( 'manage_woocommerce' ) )
229
  return $post_id;
 
230
 
231
  $shipping_method = $_POST['_wafs_shipping_method'];
232
 
@@ -262,13 +271,8 @@ class WAFS_post_type {
262
  }
263
 
264
  }
265
- $wafs_post_type = new WAFS_post_type();
266
 
267
  /**
268
  * Load condition object
269
  */
270
  require_once plugin_dir_path( __FILE__ ) . 'admin/settings/conditions/class-wafs-condition.php';
271
- /**
272
- * Load ajax methods
273
- */
274
- require_once plugin_dir_path( __FILE__ ) . '/class-wafs-ajax.php';
20
  */
21
  public function __construct() {
22
 
23
+ // Register post type
24
+ add_action( 'init', array( $this, 'wafs_register_post_type' ) );
25
 
26
+ // Add/save meta boxes
27
+ add_action( 'add_meta_boxes', array( $this, 'wafs_post_type_meta_box' ) );
28
+ add_action( 'save_post', array( $this, 'wafs_save_meta' ) );
29
+ add_action( 'save_post', array( $this, 'wafs_save_condition_meta' ) );
30
 
31
+ // Edit user messages
32
+ add_filter( 'post_updated_messages', array( $this, 'wafs_custom_post_type_messages' ) );
33
 
34
+ // Redirect after delete
35
+ add_action('load-edit.php', array( $this, 'wafs_redirect_after_trash' ) );
36
 
37
  }
38
 
47
  public function wafs_register_post_type() {
48
 
49
  $labels = array(
50
+ 'name' => __( 'Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
51
  'singular_name' => __( 'Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
52
+ 'add_new' => __( 'Add New', 'woocommerce-advanced-free-shipping' ),
53
+ 'add_new_item' => __( 'Add New Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
54
+ 'edit_item' => __( 'Edit Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
55
+ 'new_item' => __( 'New Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
56
+ 'view_item' => __( 'View Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ),
57
+ 'search_items' => __( 'Search Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
58
+ 'not_found' => __( 'No Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ),
59
+ 'not_found_in_trash' => __( 'No Advanced Free Shipping methods found in Trash', 'woocommerce-advanced-free-shipping' ),
60
  );
61
 
62
  register_post_type( 'wafs', array(
185
  */
186
  public function wafs_save_condition_meta( $post_id ) {
187
 
188
+ if ( ! isset( $_POST['wafs_conditions_meta_box_nonce'] ) ) :
189
  return $post_id;
190
+ endif;
191
 
192
  $nonce = $_POST['wafs_conditions_meta_box_nonce'];
193
 
194
+ if ( ! wp_verify_nonce( $nonce, 'wafs_conditions_meta_box' ) ) :
195
  return $post_id;
196
+ endif;
197
 
198
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) :
199
  return $post_id;
200
+ endif;
201
 
202
+ if ( ! current_user_can( 'manage_woocommerce' ) ) :
203
  return $post_id;
204
+ endif;
205
 
206
  $shipping_method_conditions = $_POST['_wafs_shipping_method_conditions'];
207
 
219
  */
220
  public function wafs_save_meta( $post_id ) {
221
 
222
+ if ( ! isset( $_POST['wafs_settings_meta_box_nonce'] ) ) :
223
  return $post_id;
224
+ endif;
225
 
226
  $nonce = $_POST['wafs_settings_meta_box_nonce'];
227
 
228
+ if ( ! wp_verify_nonce( $nonce, 'wafs_settings_meta_box' ) ) :
229
  return $post_id;
230
+ endif;
231
 
232
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) :
233
  return $post_id;
234
+ endif;
235
 
236
+ if ( ! current_user_can( 'manage_woocommerce' ) ) :
237
  return $post_id;
238
+ endif;
239
 
240
  $shipping_method = $_POST['_wafs_shipping_method'];
241
 
271
  }
272
 
273
  }
 
274
 
275
  /**
276
  * Load condition object
277
  */
278
  require_once plugin_dir_path( __FILE__ ) . 'admin/settings/conditions/class-wafs-condition.php';
 
 
 
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: sormano
3
  Donate link: http://www.jeroensormani.com/donate/
4
  Tags: woocommerce, shipping, woocommerce shipping, woocommerce free shipping, woocommerce free, woocommerce advanced free shipping, wc free shipping, wc shipping, advanced shipping, pro shipping, table rate shipping, country shipping, free shipping
5
  Requires at least: 3.6
6
- Tested up to: 3.9
7
- Stable tag: 1.0.4
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -13,7 +13,7 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
13
  == Description ==
14
  WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
15
 
16
- **Conditions like:**
17
 
18
  - Cart total
19
  - Country
@@ -28,10 +28,9 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
28
 
29
  **Translations, feature requests, ratings and donations are welcome and appreciated!**
30
 
31
- **Translations**
32
 
33
  - Spanish [(Andres Felipe)](https://wordpress.org/support/profile/naturalworldstm)
34
- - Portuguese
35
 
36
  == Installation ==
37
 
@@ -47,10 +46,16 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
 
50
  = 1.0.4 =
51
  * Fix - Weight condition wasn't working
52
  * Fix - Cash On Delivery for WAFS
53
- * Added - Added languages files for Portuguese - Brazil pt_BR
54
 
55
  = 1.0.3 =
56
  * Improvement - Customized user messages when saving shipping method
3
  Donate link: http://www.jeroensormani.com/donate/
4
  Tags: woocommerce, shipping, woocommerce shipping, woocommerce free shipping, woocommerce free, woocommerce advanced free shipping, wc free shipping, wc shipping, advanced shipping, pro shipping, table rate shipping, country shipping, free shipping
5
  Requires at least: 3.6
6
+ Tested up to: 4.1
7
+ Stable tag: 1.0.5
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
13
  == Description ==
14
  WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
15
 
16
+ *Conditions like:*
17
 
18
  - Cart total
19
  - Country
28
 
29
  **Translations, feature requests, ratings and donations are welcome and appreciated!**
30
 
31
+ ** Translations **
32
 
33
  - Spanish [(Andres Felipe)](https://wordpress.org/support/profile/naturalworldstm)
 
34
 
35
  == Installation ==
36
 
46
 
47
  == Changelog ==
48
 
49
+ = 1.0.5 - 14-12-2014 =
50
+
51
+ * Fix - Hide other shipping doesn't save in rare cases
52
+ * Improvement - Use of WC() singleton instead of $woocommerce global
53
+ * Improvement - Add background color to overview table every other row
54
+
55
  = 1.0.4 =
56
  * Fix - Weight condition wasn't working
57
  * Fix - Cash On Delivery for WAFS
58
+ * Added - Added languages files for Portugese - Brazil pt_BR
59
 
60
  = 1.0.3 =
61
  * Improvement - Customized user messages when saving shipping method
woocommerce-advanced-free-shipping.php CHANGED
@@ -1,13 +1,13 @@
1
  <?PHP
2
  /*
3
- Plugin Name: Woocommerce Advanced Free Shipping
4
- Plugin URI: http://www.jeroensormani.com/
5
- Donate link: http://www.jeroensormani.com/donate/
6
- Description: WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
7
- Version: 1.0.4
8
- Author: Jeroen Sormani
9
- Author URI: http://www.jeroensormani.com/
10
- Text Domain: woocommerce-advanced-free-shipping
11
 
12
  * Copyright Jeroen Sormani
13
  *
@@ -48,7 +48,7 @@ class WooCommerce_Advanced_Free_Shipping {
48
  * @since 1.0.4
49
  * @var string $version Plugin version number.
50
  */
51
- public $version = '1.0.4';
52
 
53
 
54
  /**
@@ -119,11 +119,58 @@ class WooCommerce_Advanced_Free_Shipping {
119
  // Load textdomain
120
  $this->load_textdomain();
121
 
 
 
122
 
123
  /**
124
  * Require matching conditions hooks.
125
  */
126
  require_once plugin_dir_path( __FILE__ ) . '/includes/class-wafs-match-conditions.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
  }
129
 
@@ -143,9 +190,6 @@ class WooCommerce_Advanced_Free_Shipping {
143
  // Add shipping method
144
  add_action( 'woocommerce_shipping_methods', array( $this, 'wafs_add_shipping_method' ) );
145
 
146
- // Register post type
147
- add_action( 'init', array( $this, 'wafs_register_post_type' ) );
148
-
149
  // Enqueue scripts
150
  add_action( 'admin_enqueue_scripts', array( $this, 'wafs_admin_enqueue_scripts' ) );
151
 
@@ -176,7 +220,11 @@ class WooCommerce_Advanced_Free_Shipping {
176
  */
177
  public function wafs_free_shipping() {
178
 
 
 
 
179
  require_once plugin_dir_path( __FILE__ ) . 'includes/class-wafs-method.php';
 
180
 
181
  }
182
 
@@ -199,26 +247,11 @@ class WooCommerce_Advanced_Free_Shipping {
199
  }
200
 
201
 
202
- /**
203
- * WAFS post type.
204
- *
205
- * Class to handle post type and everything around that.
206
- *
207
- * @since 1.0.0
208
- */
209
- public function wafs_register_post_type() {
210
-
211
- /**
212
- * Require file with settings.
213
- */
214
- require_once plugin_dir_path( __FILE__ ) . 'includes/class-wafs-post-type.php';
215
-
216
- }
217
-
218
-
219
  /**
220
  * Enqueue scripts.
221
  *
 
 
222
  * @since 1.0.0
223
  */
224
  public function wafs_admin_enqueue_scripts() {
1
  <?PHP
2
  /*
3
+ * Plugin Name: Woocommerce Advanced Free Shipping
4
+ * Plugin URI: http://www.jeroensormani.com/
5
+ * Donate link: http://www.jeroensormani.com/donate/
6
+ * Description: WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
7
+ * Version: 1.0.5
8
+ * Author: Jeroen Sormani
9
+ * Author URI: http://www.jeroensormani.com/
10
+ * Text Domain: woocommerce-advanced-free-shipping
11
 
12
  * Copyright Jeroen Sormani
13
  *
48
  * @since 1.0.4
49
  * @var string $version Plugin version number.
50
  */
51
+ public $version = '1.0.5';
52
 
53
 
54
  /**
119
  // Load textdomain
120
  $this->load_textdomain();
121
 
122
+ // Updater
123
+ $this->update();
124
 
125
  /**
126
  * Require matching conditions hooks.
127
  */
128
  require_once plugin_dir_path( __FILE__ ) . '/includes/class-wafs-match-conditions.php';
129
+ $this->matcher = new Wafs_Match_Conditions();
130
+
131
+ /**
132
+ * Require file with settings.
133
+ */
134
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-wafs-post-type.php';
135
+ $this->post_type = new WAFS_post_type();
136
+
137
+ /**
138
+ * Load ajax methods
139
+ */
140
+ require_once plugin_dir_path( __FILE__ ) . '/includes/class-wafs-ajax.php';
141
+ $this->ajax = new WAFS_Ajax();
142
+
143
+ }
144
+
145
+
146
+ /**
147
+ * Update.
148
+ *
149
+ * Update function.
150
+ *
151
+ * @since 1.0.3
152
+ */
153
+ public function update() {
154
+
155
+ $db_version = get_option( 'wafs_plugin_version', '1.0.0' );
156
+
157
+ // Stop current version is up to date
158
+ if ( $db_version >= $this->version ) :
159
+ return;
160
+ endif;
161
+
162
+ // Update functions for 1.0.3/1.0.5
163
+ if ( version_compare( '1.0.3', $db_version ) || version_compare( '1.0.5', $db_version ) ) :
164
+
165
+ $wafs_method_settings = get_option( 'woocommerce_advanced_free_shipping_settings' );
166
+ if ( isset( $wafs_method_settings['hide_other_shipping_when_available'] ) ) :
167
+ $wafs_method_settings['hide_other_shipping'] = $wafs_method_settings['hide_other_shipping_when_available'];
168
+ update_option( 'woocommerce_advanced_free_shipping_settings', $wafs_method_settings );
169
+ endif;
170
+
171
+ endif;
172
+
173
+ update_option( 'wafs_plugin_version', $this->version );
174
 
175
  }
176
 
190
  // Add shipping method
191
  add_action( 'woocommerce_shipping_methods', array( $this, 'wafs_add_shipping_method' ) );
192
 
 
 
 
193
  // Enqueue scripts
194
  add_action( 'admin_enqueue_scripts', array( $this, 'wafs_admin_enqueue_scripts' ) );
195
 
220
  */
221
  public function wafs_free_shipping() {
222
 
223
+ /**
224
+ * WAFS shipping method
225
+ */
226
  require_once plugin_dir_path( __FILE__ ) . 'includes/class-wafs-method.php';
227
+ $this->was_method = new Wafs_Free_Shipping_Method();
228
 
229
  }
230
 
247
  }
248
 
249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  /**
251
  * Enqueue scripts.
252
  *
253
+ * Enqueue javascript and stylesheets to the admin area.
254
+ *
255
  * @since 1.0.0
256
  */
257
  public function wafs_admin_enqueue_scripts() {