Version Description
16-06-2016 =
[Fix] - Fix a notice that was introduced with a change in WooCommerce 2.6
Download this release
Release Info
Developer | sormano |
Plugin | WooCommerce Advanced Free Shipping |
Version | 1.0.9 |
Comparing to | |
See all releases |
Code changes from version 1.0.8 to 1.0.9
- includes/admin/class-wafs-admin.php +3 -3
- includes/admin/settings/conditions/class-wafs-condition.php +13 -8
- includes/admin/settings/conditions/condition-conditions.php +22 -22
- includes/admin/settings/conditions/condition-descriptions.php +10 -10
- includes/admin/settings/conditions/condition-operators.php +3 -3
- includes/admin/settings/conditions/condition-values.php +20 -18
- includes/admin/settings/meta-box-conditions.php +1 -1
- includes/admin/views/conditions-table.php +6 -6
- includes/class-wafs-ajax.php +1 -0
- includes/class-wafs-match-conditions.php +101 -98
- includes/class-wafs-method.php +41 -38
- includes/class-wafs-post-type.php +31 -31
- readme.txt +7 -4
- woocommerce-advanced-free-shipping.php +14 -9
includes/admin/class-wafs-admin.php
CHANGED
@@ -82,8 +82,8 @@ class WAFS_Admin {
|
|
82 |
*
|
83 |
* @since 1.0.8
|
84 |
*
|
85 |
-
* @param
|
86 |
-
* @return
|
87 |
*/
|
88 |
public function add_screen_ids( $screen_ids ) {
|
89 |
|
@@ -106,7 +106,7 @@ class WAFS_Admin {
|
|
106 |
global $parent_file, $submenu_file, $post_type;
|
107 |
|
108 |
if ( 'wafs' == $post_type ) :
|
109 |
-
$parent_file
|
110 |
$submenu_file = 'wc-settings';
|
111 |
endif;
|
112 |
|
82 |
*
|
83 |
* @since 1.0.8
|
84 |
*
|
85 |
+
* @param array $screen_ids List of existing screen IDs.
|
86 |
+
* @return array List of modified screen IDs.
|
87 |
*/
|
88 |
public function add_screen_ids( $screen_ids ) {
|
89 |
|
106 |
global $parent_file, $submenu_file, $post_type;
|
107 |
|
108 |
if ( 'wafs' == $post_type ) :
|
109 |
+
$parent_file = 'woocommerce';
|
110 |
$submenu_file = 'wc-settings';
|
111 |
endif;
|
112 |
|
includes/admin/settings/conditions/class-wafs-condition.php
CHANGED
@@ -72,16 +72,17 @@ class WAFS_Condition {
|
|
72 |
*/
|
73 |
public function __construct( $id = null, $group = 0, $condition = null, $operator = null, $value = null ) {
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
|
82 |
-
|
|
|
83 |
|
84 |
-
|
85 |
|
86 |
}
|
87 |
|
@@ -165,9 +166,11 @@ class WAFS_Condition {
|
|
165 |
* @since 1.0.0
|
166 |
*/
|
167 |
public function wafs_add_condition_button() {
|
|
|
168 |
?>
|
169 |
<a class='button condition-add' data-group='<?php echo absint( $this->group ); ?>' href='javascript:void(0);'>+</a>
|
170 |
<?php
|
|
|
171 |
}
|
172 |
|
173 |
|
@@ -179,9 +182,11 @@ class WAFS_Condition {
|
|
179 |
* @since 1.0.0
|
180 |
*/
|
181 |
public function wafs_remove_condition_button() {
|
|
|
182 |
?>
|
183 |
<a class='button condition-delete' href='javascript:void(0);'>-</a>
|
184 |
<?php
|
|
|
185 |
}
|
186 |
|
187 |
|
72 |
*/
|
73 |
public function __construct( $id = null, $group = 0, $condition = null, $operator = null, $value = null ) {
|
74 |
|
75 |
+
$this->id = $id;
|
76 |
+
$this->group = $group;
|
77 |
+
$this->condition = $condition;
|
78 |
+
$this->operator = $operator;
|
79 |
+
$this->value = $value;
|
80 |
|
81 |
+
if ( ! $id ) {
|
82 |
+
$this->id = rand();
|
83 |
+
}
|
84 |
|
85 |
+
$this->wafs_create_object();
|
86 |
|
87 |
}
|
88 |
|
166 |
* @since 1.0.0
|
167 |
*/
|
168 |
public function wafs_add_condition_button() {
|
169 |
+
|
170 |
?>
|
171 |
<a class='button condition-add' data-group='<?php echo absint( $this->group ); ?>' href='javascript:void(0);'>+</a>
|
172 |
<?php
|
173 |
+
|
174 |
}
|
175 |
|
176 |
|
182 |
* @since 1.0.0
|
183 |
*/
|
184 |
public function wafs_remove_condition_button() {
|
185 |
+
|
186 |
?>
|
187 |
<a class='button condition-delete' href='javascript:void(0);'>-</a>
|
188 |
<?php
|
189 |
+
|
190 |
}
|
191 |
|
192 |
|
includes/admin/settings/conditions/condition-conditions.php
CHANGED
@@ -8,37 +8,37 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
8 |
*
|
9 |
* @since 1.0.0
|
10 |
*
|
11 |
-
* @param
|
12 |
-
* @param
|
13 |
-
* @param
|
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'
|
20 |
-
'subtotal_ex_tax'
|
21 |
-
'tax'
|
22 |
-
'quantity'
|
23 |
-
'contains_product'
|
24 |
-
'coupon'
|
25 |
-
'weight'
|
26 |
-
'contains_shipping_class'
|
27 |
),
|
28 |
__( 'User Details', 'woocommerce-advanced-free-shipping' ) => array(
|
29 |
-
'zipcode'
|
30 |
-
'city'
|
31 |
-
'state'
|
32 |
-
'country'
|
33 |
-
'role'
|
34 |
),
|
35 |
__( 'Product', 'woocommerce-advanced-free-shipping' ) => array(
|
36 |
-
'width'
|
37 |
-
'height'
|
38 |
-
'length'
|
39 |
-
'stock'
|
40 |
-
'stock_status'
|
41 |
-
'category'
|
42 |
),
|
43 |
);
|
44 |
|
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 |
|
includes/admin/settings/conditions/condition-descriptions.php
CHANGED
@@ -8,20 +8,20 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
8 |
*
|
9 |
* @since 1.0.0
|
10 |
*
|
11 |
-
* @param
|
12 |
*/
|
13 |
function wafs_condition_description( $condition ) {
|
14 |
|
15 |
$descriptions = array(
|
16 |
-
'state'
|
17 |
-
'weight'
|
18 |
-
'length'
|
19 |
-
'width'
|
20 |
-
'height'
|
21 |
-
'stock_status'
|
22 |
-
'category'
|
23 |
-
'contains_product'
|
24 |
-
'contains_shipping_class'
|
25 |
);
|
26 |
|
27 |
$descriptions = apply_filters( 'wafs_descriptions', $descriptions );
|
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 );
|
includes/admin/settings/conditions/condition-operators.php
CHANGED
@@ -8,9 +8,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
8 |
*
|
9 |
* @since 1.0.0
|
10 |
*
|
11 |
-
* @param
|
12 |
-
* @param
|
13 |
-
* @param
|
14 |
*/
|
15 |
function wafs_condition_operator( $id, $group = 0, $current_value = '==' ) {
|
16 |
|
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 |
|
includes/admin/settings/conditions/condition-values.php
CHANGED
@@ -8,10 +8,10 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
8 |
*
|
9 |
* @since 1.0.0
|
10 |
*
|
11 |
-
* @param
|
12 |
-
* @param
|
13 |
-
* @param
|
14 |
-
* @param
|
15 |
*/
|
16 |
function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $current_value = '' ) {
|
17 |
|
@@ -51,7 +51,7 @@ function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $curre
|
|
51 |
|
52 |
$products = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'product', 'order' => 'asc', 'orderby' => 'title' ) );
|
53 |
foreach ( $products as $product ) :
|
54 |
-
$values['options'][$product->ID ] = $product->post_title;
|
55 |
endforeach;
|
56 |
|
57 |
break;
|
@@ -100,18 +100,18 @@ function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $curre
|
|
100 |
|
101 |
$values['field'] = 'select';
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
|
112 |
-
|
113 |
|
114 |
-
|
115 |
|
116 |
break;
|
117 |
|
@@ -164,8 +164,8 @@ function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $curre
|
|
164 |
|
165 |
$values['field'] = 'select';
|
166 |
$values['options'] = array(
|
167 |
-
'instock'
|
168 |
-
'outofstock'
|
169 |
);
|
170 |
|
171 |
break;
|
@@ -208,16 +208,18 @@ function wafs_condition_values( $id, $group = 0, $condition = 'subtotal', $curre
|
|
208 |
case 'select' :
|
209 |
|
210 |
// Backwards compatibility for extensions
|
211 |
-
|
|
|
|
|
212 |
?><select class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo absint( $group ); ?>][<?php echo absint( $id ); ?>][value]'>
|
213 |
|
214 |
-
<option <?php selected( '', $current_value ); ?>><?php _e( 'Select option'
|
215 |
foreach ( $values['options'] as $key => $value ) :
|
216 |
|
217 |
if ( ! is_array( $value ) ) :
|
218 |
?><option value='<?php echo esc_attr( $key ); ?>' <?php selected( $key, $current_value ); ?>><?php echo esc_html( $value ); ?></option><?php
|
219 |
else :
|
220 |
-
?><optgroup label='<?php echo $key ?>'><?php
|
221 |
foreach ( $value as $k => $v ) :
|
222 |
?><option value='<?php echo esc_attr( $k ); ?>' <?php selected( $k, $current_value ); ?>><?php echo esc_html( $v ); ?></option><?php
|
223 |
endforeach;
|
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 |
|
51 |
|
52 |
$products = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'product', 'order' => 'asc', 'orderby' => 'title' ) );
|
53 |
foreach ( $products as $product ) :
|
54 |
+
$values['options'][ $product->ID ] = $product->post_title;
|
55 |
endforeach;
|
56 |
|
57 |
break;
|
100 |
|
101 |
$values['field'] = 'select';
|
102 |
|
103 |
+
foreach ( WC()->countries->states as $country => $states ) :
|
104 |
|
105 |
+
if ( empty( $states ) ) continue; // Don't show country if it has no states
|
106 |
+
if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries
|
107 |
|
108 |
+
foreach ( $states as $state_key => $state ) :
|
109 |
+
$country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state;
|
110 |
+
endforeach;
|
111 |
|
112 |
+
$values['options'] = $country_states;
|
113 |
|
114 |
+
endforeach;
|
115 |
|
116 |
break;
|
117 |
|
164 |
|
165 |
$values['field'] = 'select';
|
166 |
$values['options'] = array(
|
167 |
+
'instock' => __( 'In stock', 'woocommerce-advanced-free-shipping' ),
|
168 |
+
'outofstock' => __( 'Out of stock', 'woocommerce-advanced-free-shipping' ),
|
169 |
);
|
170 |
|
171 |
break;
|
208 |
case 'select' :
|
209 |
|
210 |
// Backwards compatibility for extensions
|
211 |
+
if ( isset( $values['values'] ) ) {
|
212 |
+
@array_merge( $values['options'], $values['values'] );
|
213 |
+
}
|
214 |
?><select class='wafs-value' name='_wafs_shipping_method_conditions[<?php echo absint( $group ); ?>][<?php echo absint( $id ); ?>][value]'>
|
215 |
|
216 |
+
<option <?php selected( '', $current_value ); ?>><?php _e( 'Select option', 'woocommerce-advanced-free-shipping' ); ?></option><?php
|
217 |
foreach ( $values['options'] as $key => $value ) :
|
218 |
|
219 |
if ( ! is_array( $value ) ) :
|
220 |
?><option value='<?php echo esc_attr( $key ); ?>' <?php selected( $key, $current_value ); ?>><?php echo esc_html( $value ); ?></option><?php
|
221 |
else :
|
222 |
+
?><optgroup label='<?php echo $key; ?>'><?php
|
223 |
foreach ( $value as $k => $v ) :
|
224 |
?><option value='<?php echo esc_attr( $k ); ?>' <?php selected( $k, $current_value ); ?>><?php echo esc_html( $v ); ?></option><?php
|
225 |
endforeach;
|
includes/admin/settings/meta-box-conditions.php
CHANGED
@@ -20,7 +20,7 @@ $conditions = get_post_meta( $post->ID, '_wafs_shipping_method_conditions', true
|
|
20 |
|
21 |
<p><strong><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
|
22 |
|
23 |
-
if ( !empty( $conditions ) ) :
|
24 |
|
25 |
foreach ( $conditions as $condition_group => $conditions ) :
|
26 |
|
20 |
|
21 |
<p><strong><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
|
22 |
|
23 |
+
if ( ! empty( $conditions ) ) :
|
24 |
|
25 |
foreach ( $conditions as $condition_group => $conditions ) :
|
26 |
|
includes/admin/views/conditions-table.php
CHANGED
@@ -34,14 +34,14 @@ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' =>
|
|
34 |
foreach ( $method_conditions as $method_condition ) :
|
35 |
|
36 |
$method_details = get_post_meta( $method_condition->ID, '_wafs_shipping_method', true );
|
37 |
-
$conditions
|
38 |
-
$alt
|
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' ); ?>'>
|
44 |
-
<?php echo empty( $method_condition->post_title) ? __( 'Untitled', 'woocommerce-advanced-free-shipping' ) : esc_html( $method_condition->post_title ); ?>
|
45 |
</a>
|
46 |
</strong>
|
47 |
<div class='row-actions'>
|
@@ -49,7 +49,7 @@ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' =>
|
|
49 |
<a href='<?php echo get_edit_post_link( $method_condition->ID ); ?>' title='<?php _e( 'Edit Method', 'woocommerce-advanced-free-shipping' ); ?>'>
|
50 |
<?php _e( 'Edit', 'woocommerce-advanced-free-shipping' ); ?>
|
51 |
</a>
|
52 |
-
|
53 |
</span>
|
54 |
<span class='trash'>
|
55 |
<a href='<?php echo get_delete_post_link( $method_condition->ID ); ?>' title='<?php _e( 'Delete Method', 'woocommerce-advanced-free-shipping' ); ?>'><?php
|
@@ -58,7 +58,7 @@ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' =>
|
|
58 |
</span>
|
59 |
</div>
|
60 |
</td>
|
61 |
-
<td><?php echo empty( $method_details['shipping_title'] ) ? __( 'Free Shipping', 'woocommerce-advanced-free-shipping') : esc_html( $method_details['shipping_title'] ); ?></td>
|
62 |
<td><?php echo count( $conditions ); ?></td>
|
63 |
</td>
|
64 |
</tr><?php
|
@@ -82,4 +82,4 @@ $method_conditions = get_posts( array( 'posts_per_page' => '-1', 'post_type' =>
|
|
82 |
</tfoot>
|
83 |
</table>
|
84 |
</td>
|
85 |
-
</tr>
|
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' ); ?>'>
|
44 |
+
<?php echo empty( $method_condition->post_title ) ? __( 'Untitled', 'woocommerce-advanced-free-shipping' ) : esc_html( $method_condition->post_title ); ?>
|
45 |
</a>
|
46 |
</strong>
|
47 |
<div class='row-actions'>
|
49 |
<a href='<?php echo get_edit_post_link( $method_condition->ID ); ?>' title='<?php _e( 'Edit Method', 'woocommerce-advanced-free-shipping' ); ?>'>
|
50 |
<?php _e( 'Edit', 'woocommerce-advanced-free-shipping' ); ?>
|
51 |
</a>
|
52 |
+
|
|
53 |
</span>
|
54 |
<span class='trash'>
|
55 |
<a href='<?php echo get_delete_post_link( $method_condition->ID ); ?>' title='<?php _e( 'Delete Method', 'woocommerce-advanced-free-shipping' ); ?>'><?php
|
58 |
</span>
|
59 |
</div>
|
60 |
</td>
|
61 |
+
<td><?php echo empty( $method_details['shipping_title'] ) ? __( 'Free Shipping', 'woocommerce-advanced-free-shipping' ) : esc_html( $method_details['shipping_title'] ); ?></td>
|
62 |
<td><?php echo count( $conditions ); ?></td>
|
63 |
</td>
|
64 |
</tr><?php
|
82 |
</tfoot>
|
83 |
</table>
|
84 |
</td>
|
85 |
+
</tr>
|
includes/class-wafs-ajax.php
CHANGED
@@ -72,6 +72,7 @@ class WAFS_Ajax {
|
|
72 |
<p><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
|
73 |
|
74 |
die();
|
|
|
75 |
}
|
76 |
|
77 |
|
72 |
<p><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php
|
73 |
|
74 |
die();
|
75 |
+
|
76 |
}
|
77 |
|
78 |
|
includes/class-wafs-match-conditions.php
CHANGED
@@ -20,27 +20,27 @@ class WAFS_Match_Conditions {
|
|
20 |
*/
|
21 |
public function __construct() {
|
22 |
|
23 |
-
add_filter( 'wafs_match_condition_subtotal',
|
24 |
-
add_filter( 'wafs_match_condition_subtotal_ex_tax',
|
25 |
-
add_filter( 'wafs_match_condition_tax',
|
26 |
-
add_filter( 'wafs_match_condition_quantity',
|
27 |
-
add_filter( 'wafs_match_condition_contains_product',
|
28 |
-
add_filter( 'wafs_match_condition_coupon',
|
29 |
-
add_filter( 'wafs_match_condition_weight',
|
30 |
-
add_filter( 'wafs_match_condition_contains_shipping_class',
|
31 |
-
|
32 |
-
add_filter( 'wafs_match_condition_zipcode',
|
33 |
-
add_filter( 'wafs_match_condition_city',
|
34 |
-
add_filter( 'wafs_match_condition_state',
|
35 |
-
add_filter( 'wafs_match_condition_country',
|
36 |
-
add_filter( 'wafs_match_condition_role',
|
37 |
-
|
38 |
-
add_filter( 'wafs_match_condition_width',
|
39 |
-
add_filter( 'wafs_match_condition_height',
|
40 |
-
add_filter( 'wafs_match_condition_length',
|
41 |
-
add_filter( 'wafs_match_condition_stock',
|
42 |
-
add_filter( 'wafs_match_condition_stock_status',
|
43 |
-
add_filter( 'wafs_match_condition_category',
|
44 |
|
45 |
}
|
46 |
|
@@ -52,10 +52,10 @@ class WAFS_Match_Conditions {
|
|
52 |
*
|
53 |
* @since 1.0.0
|
54 |
*
|
55 |
-
* @param
|
56 |
-
* @param
|
57 |
-
* @param
|
58 |
-
* @return
|
59 |
*/
|
60 |
public function wafs_match_condition_subtotal( $match, $operator, $value ) {
|
61 |
|
@@ -83,10 +83,10 @@ class WAFS_Match_Conditions {
|
|
83 |
*
|
84 |
* @since 1.0.0
|
85 |
*
|
86 |
-
* @param
|
87 |
-
* @param
|
88 |
-
* @param
|
89 |
-
* @return
|
90 |
*/
|
91 |
public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
|
92 |
|
@@ -114,10 +114,10 @@ class WAFS_Match_Conditions {
|
|
114 |
*
|
115 |
* @since 1.0.0
|
116 |
*
|
117 |
-
* @param
|
118 |
-
* @param
|
119 |
-
* @param
|
120 |
-
* @return
|
121 |
*/
|
122 |
public function wafs_match_condition_tax( $match, $operator, $value ) {
|
123 |
|
@@ -148,10 +148,10 @@ class WAFS_Match_Conditions {
|
|
148 |
*
|
149 |
* @since 1.0.0
|
150 |
*
|
151 |
-
* @param
|
152 |
-
* @param
|
153 |
-
* @param
|
154 |
-
* @return
|
155 |
*/
|
156 |
public function wafs_match_condition_quantity( $match, $operator, $value ) {
|
157 |
|
@@ -179,10 +179,10 @@ class WAFS_Match_Conditions {
|
|
179 |
*
|
180 |
* @since 1.0.0
|
181 |
*
|
182 |
-
* @param
|
183 |
-
* @param
|
184 |
-
* @param
|
185 |
-
* @return
|
186 |
*/
|
187 |
public function wafs_match_condition_contains_product( $match, $operator, $value ) {
|
188 |
|
@@ -210,10 +210,10 @@ class WAFS_Match_Conditions {
|
|
210 |
*
|
211 |
* @since 1.0.0
|
212 |
*
|
213 |
-
* @param
|
214 |
-
* @param
|
215 |
-
* @param
|
216 |
-
* @return
|
217 |
*/
|
218 |
public function wafs_match_condition_coupon( $match, $operator, $value ) {
|
219 |
|
@@ -237,10 +237,10 @@ class WAFS_Match_Conditions {
|
|
237 |
*
|
238 |
* @since 1.0.0
|
239 |
*
|
240 |
-
* @param
|
241 |
-
* @param
|
242 |
-
* @param
|
243 |
-
* @return
|
244 |
*/
|
245 |
public function wafs_match_condition_weight( $match, $operator, $value ) {
|
246 |
|
@@ -283,8 +283,8 @@ class WAFS_Match_Conditions {
|
|
283 |
|
284 |
foreach ( WC()->cart->cart_contents as $product ) :
|
285 |
|
286 |
-
$id
|
287 |
-
$product
|
288 |
|
289 |
if ( $operator == '==' ) :
|
290 |
if ( $product->get_shipping_class() == $value ) :
|
@@ -315,10 +315,10 @@ class WAFS_Match_Conditions {
|
|
315 |
*
|
316 |
* @since 1.0.2; $value may contain single or comma (,) separated zipcodes.
|
317 |
*
|
318 |
-
* @param
|
319 |
-
* @param
|
320 |
-
* @param
|
321 |
-
* @return
|
322 |
*/
|
323 |
public function wafs_match_condition_zipcode( $match, $operator, $value ) {
|
324 |
|
@@ -358,10 +358,10 @@ class WAFS_Match_Conditions {
|
|
358 |
*
|
359 |
* @since 1.0.0
|
360 |
*
|
361 |
-
* @param
|
362 |
-
* @param
|
363 |
-
* @param
|
364 |
-
* @return
|
365 |
*/
|
366 |
public function wafs_match_condition_city( $match, $operator, $value ) {
|
367 |
|
@@ -385,10 +385,10 @@ class WAFS_Match_Conditions {
|
|
385 |
*
|
386 |
* @since 1.0.0
|
387 |
*
|
388 |
-
* @param
|
389 |
-
* @param
|
390 |
-
* @param
|
391 |
-
* @return
|
392 |
*/
|
393 |
public function wafs_match_condition_state( $match, $operator, $value ) {
|
394 |
|
@@ -414,10 +414,10 @@ class WAFS_Match_Conditions {
|
|
414 |
*
|
415 |
* @since 1.0.0
|
416 |
*
|
417 |
-
* @param
|
418 |
-
* @param
|
419 |
-
* @param
|
420 |
-
* @return
|
421 |
*/
|
422 |
public function wafs_match_condition_country( $match, $operator, $value ) {
|
423 |
|
@@ -442,10 +442,10 @@ class WAFS_Match_Conditions {
|
|
442 |
* @since 1.0.0
|
443 |
* @global object $current_user Current user object for capabilities.
|
444 |
*
|
445 |
-
* @param
|
446 |
-
* @param
|
447 |
-
* @param
|
448 |
-
* @return
|
449 |
*/
|
450 |
public function wafs_match_condition_role( $match, $operator, $value ) {
|
451 |
|
@@ -474,10 +474,10 @@ class WAFS_Match_Conditions {
|
|
474 |
*
|
475 |
* @since 1.0.0
|
476 |
*
|
477 |
-
* @param
|
478 |
-
* @param
|
479 |
-
* @param
|
480 |
-
* @return
|
481 |
*/
|
482 |
public function wafs_match_condition_width( $match, $operator, $value ) {
|
483 |
|
@@ -517,10 +517,10 @@ class WAFS_Match_Conditions {
|
|
517 |
*
|
518 |
* @since 1.0.0
|
519 |
*
|
520 |
-
* @param
|
521 |
-
* @param
|
522 |
-
* @param
|
523 |
-
* @return
|
524 |
*/
|
525 |
public function wafs_match_condition_height( $match, $operator, $value ) {
|
526 |
|
@@ -560,10 +560,10 @@ class WAFS_Match_Conditions {
|
|
560 |
*
|
561 |
* @since 1.0.0
|
562 |
*
|
563 |
-
* @param
|
564 |
-
* @param
|
565 |
-
* @param
|
566 |
-
* @return
|
567 |
*/
|
568 |
public function wafs_match_condition_length( $match, $operator, $value ) {
|
569 |
|
@@ -603,10 +603,10 @@ class WAFS_Match_Conditions {
|
|
603 |
*
|
604 |
* @since 1.0.0
|
605 |
*
|
606 |
-
* @param
|
607 |
-
* @param
|
608 |
-
* @param
|
609 |
-
* @return
|
610 |
*/
|
611 |
public function wafs_match_condition_stock( $match, $operator, $value ) {
|
612 |
|
@@ -615,7 +615,7 @@ class WAFS_Match_Conditions {
|
|
615 |
foreach ( WC()->cart->cart_contents as $product ) :
|
616 |
|
617 |
$product_id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
|
618 |
-
$stock[]
|
619 |
|
620 |
endforeach;
|
621 |
|
@@ -643,10 +643,10 @@ class WAFS_Match_Conditions {
|
|
643 |
*
|
644 |
* @since 1.0.0
|
645 |
*
|
646 |
-
* @param
|
647 |
-
* @param
|
648 |
-
* @param
|
649 |
-
* @return
|
650 |
*/
|
651 |
public function wafs_match_condition_stock_status( $match, $operator, $value ) {
|
652 |
|
@@ -656,16 +656,18 @@ class WAFS_Match_Conditions {
|
|
656 |
|
657 |
$match = true;
|
658 |
foreach ( WC()->cart->cart_contents as $product ) :
|
659 |
-
if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value )
|
660 |
$match = false;
|
|
|
661 |
endforeach;
|
662 |
|
663 |
elseif ( '!=' == $operator ) :
|
664 |
|
665 |
$match = true;
|
666 |
foreach ( WC()->cart->cart_contents as $product ) :
|
667 |
-
if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value )
|
668 |
$match = false;
|
|
|
669 |
endforeach;
|
670 |
|
671 |
endif;
|
@@ -683,10 +685,10 @@ class WAFS_Match_Conditions {
|
|
683 |
*
|
684 |
* @since 1.0.0
|
685 |
*
|
686 |
-
* @param
|
687 |
-
* @param
|
688 |
-
* @param
|
689 |
-
* @return
|
690 |
*/
|
691 |
public function wafs_match_condition_category( $match, $operator, $value ) {
|
692 |
|
@@ -720,4 +722,5 @@ class WAFS_Match_Conditions {
|
|
720 |
|
721 |
}
|
722 |
|
|
|
723 |
}
|
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.
|
58 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
59 |
*/
|
60 |
public function wafs_match_condition_subtotal( $match, $operator, $value ) {
|
61 |
|
83 |
*
|
84 |
* @since 1.0.0
|
85 |
*
|
86 |
+
* @param bool $match Current match value.
|
87 |
+
* @param string $operator Operator selected by the user in the condition row.
|
88 |
+
* @param mixed $value Value given by the user in the condition row.
|
89 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
90 |
*/
|
91 |
public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) {
|
92 |
|
114 |
*
|
115 |
* @since 1.0.0
|
116 |
*
|
117 |
+
* @param bool $match Current match value.
|
118 |
+
* @param string $operator Operator selected by the user in the condition row.
|
119 |
+
* @param mixed $value Value given by the user in the condition row.
|
120 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
121 |
*/
|
122 |
public function wafs_match_condition_tax( $match, $operator, $value ) {
|
123 |
|
148 |
*
|
149 |
* @since 1.0.0
|
150 |
*
|
151 |
+
* @param bool $match Current match value.
|
152 |
+
* @param string $operator Operator selected by the user in the condition row.
|
153 |
+
* @param mixed $value Value given by the user in the condition row.
|
154 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
155 |
*/
|
156 |
public function wafs_match_condition_quantity( $match, $operator, $value ) {
|
157 |
|
179 |
*
|
180 |
* @since 1.0.0
|
181 |
*
|
182 |
+
* @param bool $match Current match value.
|
183 |
+
* @param string $operator Operator selected by the user in the condition row.
|
184 |
+
* @param mixed $value Value given by the user in the condition row.
|
185 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
186 |
*/
|
187 |
public function wafs_match_condition_contains_product( $match, $operator, $value ) {
|
188 |
|
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.
|
216 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
217 |
*/
|
218 |
public function wafs_match_condition_coupon( $match, $operator, $value ) {
|
219 |
|
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.
|
243 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
244 |
*/
|
245 |
public function wafs_match_condition_weight( $match, $operator, $value ) {
|
246 |
|
283 |
|
284 |
foreach ( WC()->cart->cart_contents as $product ) :
|
285 |
|
286 |
+
$id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
|
287 |
+
$product = get_product( $id );
|
288 |
|
289 |
if ( $operator == '==' ) :
|
290 |
if ( $product->get_shipping_class() == $value ) :
|
315 |
*
|
316 |
* @since 1.0.2; $value may contain single or comma (,) separated zipcodes.
|
317 |
*
|
318 |
+
* @param bool $match Current match value.
|
319 |
+
* @param string $operator Operator selected by the user in the condition row.
|
320 |
+
* @param mixed $value Value given by the user in the condition row.
|
321 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
322 |
*/
|
323 |
public function wafs_match_condition_zipcode( $match, $operator, $value ) {
|
324 |
|
358 |
*
|
359 |
* @since 1.0.0
|
360 |
*
|
361 |
+
* @param bool $match Current match value.
|
362 |
+
* @param string $operator Operator selected by the user in the condition row.
|
363 |
+
* @param mixed $value Value given by the user in the condition row.
|
364 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
365 |
*/
|
366 |
public function wafs_match_condition_city( $match, $operator, $value ) {
|
367 |
|
385 |
*
|
386 |
* @since 1.0.0
|
387 |
*
|
388 |
+
* @param bool $match Current match value.
|
389 |
+
* @param string $operator Operator selected by the user in the condition row.
|
390 |
+
* @param mixed $value Value given by the user in the condition row.
|
391 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
392 |
*/
|
393 |
public function wafs_match_condition_state( $match, $operator, $value ) {
|
394 |
|
414 |
*
|
415 |
* @since 1.0.0
|
416 |
*
|
417 |
+
* @param bool $match Current match value.
|
418 |
+
* @param string $operator Operator selected by the user in the condition row.
|
419 |
+
* @param mixed $value Value given by the user in the condition row.
|
420 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
421 |
*/
|
422 |
public function wafs_match_condition_country( $match, $operator, $value ) {
|
423 |
|
442 |
* @since 1.0.0
|
443 |
* @global object $current_user Current user object for capabilities.
|
444 |
*
|
445 |
+
* @param bool $match Current match value.
|
446 |
+
* @param string $operator Operator selected by the user in the condition row.
|
447 |
+
* @param mixed $value Value given by the user in the condition row.
|
448 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
449 |
*/
|
450 |
public function wafs_match_condition_role( $match, $operator, $value ) {
|
451 |
|
474 |
*
|
475 |
* @since 1.0.0
|
476 |
*
|
477 |
+
* @param bool $match Current match value.
|
478 |
+
* @param string $operator Operator selected by the user in the condition row.
|
479 |
+
* @param mixed $value Value given by the user in the condition row.
|
480 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
481 |
*/
|
482 |
public function wafs_match_condition_width( $match, $operator, $value ) {
|
483 |
|
517 |
*
|
518 |
* @since 1.0.0
|
519 |
*
|
520 |
+
* @param bool $match Current match value.
|
521 |
+
* @param string $operator Operator selected by the user in the condition row.
|
522 |
+
* @param mixed $value Value given by the user in the condition row.
|
523 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
524 |
*/
|
525 |
public function wafs_match_condition_height( $match, $operator, $value ) {
|
526 |
|
560 |
*
|
561 |
* @since 1.0.0
|
562 |
*
|
563 |
+
* @param bool $match Current match value.
|
564 |
+
* @param string $operator Operator selected by the user in the condition row.
|
565 |
+
* @param mixed $value Value given by the user in the condition row.
|
566 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
567 |
*/
|
568 |
public function wafs_match_condition_length( $match, $operator, $value ) {
|
569 |
|
603 |
*
|
604 |
* @since 1.0.0
|
605 |
*
|
606 |
+
* @param bool $match Current match value.
|
607 |
+
* @param string $operator Operator selected by the user in the condition row.
|
608 |
+
* @param mixed $value Value given by the user in the condition row.
|
609 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
610 |
*/
|
611 |
public function wafs_match_condition_stock( $match, $operator, $value ) {
|
612 |
|
615 |
foreach ( WC()->cart->cart_contents as $product ) :
|
616 |
|
617 |
$product_id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
|
618 |
+
$stock[] = get_post_meta( $product_id, '_stock', true );
|
619 |
|
620 |
endforeach;
|
621 |
|
643 |
*
|
644 |
* @since 1.0.0
|
645 |
*
|
646 |
+
* @param bool $match Current match value.
|
647 |
+
* @param string $operator Operator selected by the user in the condition row.
|
648 |
+
* @param mixed $value Value given by the user in the condition row.
|
649 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
650 |
*/
|
651 |
public function wafs_match_condition_stock_status( $match, $operator, $value ) {
|
652 |
|
656 |
|
657 |
$match = true;
|
658 |
foreach ( WC()->cart->cart_contents as $product ) :
|
659 |
+
if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value ) {
|
660 |
$match = false;
|
661 |
+
}
|
662 |
endforeach;
|
663 |
|
664 |
elseif ( '!=' == $operator ) :
|
665 |
|
666 |
$match = true;
|
667 |
foreach ( WC()->cart->cart_contents as $product ) :
|
668 |
+
if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value ) {
|
669 |
$match = false;
|
670 |
+
}
|
671 |
endforeach;
|
672 |
|
673 |
endif;
|
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.
|
691 |
+
* @return BOOL Matching result, TRUE if results match, otherwise FALSE.
|
692 |
*/
|
693 |
public function wafs_match_condition_category( $match, $operator, $value ) {
|
694 |
|
722 |
|
723 |
}
|
724 |
|
725 |
+
|
726 |
}
|
includes/class-wafs-method.php
CHANGED
@@ -14,12 +14,12 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
14 |
*/
|
15 |
public function __construct() {
|
16 |
|
17 |
-
$this->id
|
18 |
-
$this->title
|
19 |
-
$this->method_title
|
20 |
-
$this->method_description
|
21 |
|
22 |
-
$this->matched_methods
|
23 |
|
24 |
$this->init();
|
25 |
|
@@ -38,8 +38,8 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
38 |
$this->init_form_fields();
|
39 |
$this->init_settings();
|
40 |
|
41 |
-
$this->enabled
|
42 |
-
$this->hide_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' ) );
|
@@ -57,7 +57,7 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
57 |
*
|
58 |
* @since 1.0.0
|
59 |
*
|
60 |
-
* @return
|
61 |
*/
|
62 |
public function wafs_match_methods() {
|
63 |
|
@@ -90,8 +90,8 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
90 |
*
|
91 |
* @since 1.0.0
|
92 |
*
|
93 |
-
* @param
|
94 |
-
* @return
|
95 |
*/
|
96 |
public function wafs_match_conditions( $condition_groups = array() ) {
|
97 |
|
@@ -122,6 +122,7 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
122 |
|
123 |
}
|
124 |
|
|
|
125 |
/**
|
126 |
* Init fields.
|
127 |
*
|
@@ -133,19 +134,19 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
133 |
|
134 |
$this->form_fields = array(
|
135 |
'enabled' => array(
|
136 |
-
'title'
|
137 |
-
'type'
|
138 |
-
'label'
|
139 |
-
'default'
|
140 |
),
|
141 |
'hide_other_shipping' => array(
|
142 |
-
'title'
|
143 |
-
'type'
|
144 |
-
'label'
|
145 |
-
'default'
|
146 |
),
|
147 |
-
'conditions'
|
148 |
-
'type'
|
149 |
)
|
150 |
);
|
151 |
|
@@ -159,7 +160,7 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
159 |
*
|
160 |
* @since 1.0.0
|
161 |
*
|
162 |
-
* @return
|
163 |
*/
|
164 |
public function generate_conditions_table_html() {
|
165 |
|
@@ -182,11 +183,13 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
182 |
*
|
183 |
* @since 1.0.0
|
184 |
*
|
185 |
-
* @param
|
186 |
-
* @return
|
187 |
*/
|
188 |
public function validate_additional_conditions_table_field( $key ) {
|
|
|
189 |
return false;
|
|
|
190 |
}
|
191 |
|
192 |
|
@@ -197,19 +200,19 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
197 |
*
|
198 |
* @since 1.0.0
|
199 |
*
|
200 |
-
* @param
|
201 |
*/
|
202 |
-
public function calculate_shipping( $package ) {
|
203 |
|
204 |
if ( false == $this->matched_methods || 'no' == $this->enabled ) return;
|
205 |
|
206 |
-
$method_args
|
207 |
-
$label
|
208 |
|
209 |
$rate = array(
|
210 |
-
'id'
|
211 |
-
'label'
|
212 |
-
'cost'
|
213 |
);
|
214 |
|
215 |
// Register the rate
|
@@ -225,26 +228,26 @@ class Wafs_Free_Shipping_Method extends WC_Shipping_Method {
|
|
225 |
*
|
226 |
* @since 1.0.0
|
227 |
*
|
228 |
-
* @param
|
229 |
-
* @return
|
230 |
*/
|
231 |
public function hide_all_shipping_when_free_is_available( $available_methods ) {
|
232 |
|
233 |
if ( 'no' == $this->hide_shipping ) return $available_methods;
|
234 |
|
235 |
-
|
236 |
|
237 |
return array( 'advanced_free_shipping' => $available_methods['advanced_free_shipping'] );
|
238 |
|
239 |
-
|
240 |
|
241 |
-
|
242 |
|
243 |
-
|
244 |
|
245 |
-
|
246 |
|
247 |
-
|
248 |
|
249 |
}
|
250 |
|
14 |
*/
|
15 |
public function __construct() {
|
16 |
|
17 |
+
$this->id = 'advanced_free_shipping';
|
18 |
+
$this->title = __( 'Free Shipping (configurable per rate)', 'woocommerce-advanced-free-shipping' );
|
19 |
+
$this->method_title = __( 'Advanced Free Shipping', 'woocommerce-advanced-free-shipping' );
|
20 |
+
$this->method_description = __( 'Configure WooCommerce Advanced Free Shipping' );
|
21 |
|
22 |
+
$this->matched_methods = $this->wafs_match_methods();
|
23 |
|
24 |
$this->init();
|
25 |
|
38 |
$this->init_form_fields();
|
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' ) );
|
57 |
*
|
58 |
* @since 1.0.0
|
59 |
*
|
60 |
+
* @return array Only the first matched method (since you won't need two free shipping).
|
61 |
*/
|
62 |
public function wafs_match_methods() {
|
63 |
|
90 |
*
|
91 |
* @since 1.0.0
|
92 |
*
|
93 |
+
* @param array $condition_groups All condition groups set by the user.
|
94 |
+
* @return BOOL True if one of the conditions groups matches.
|
95 |
*/
|
96 |
public function wafs_match_conditions( $condition_groups = array() ) {
|
97 |
|
122 |
|
123 |
}
|
124 |
|
125 |
+
|
126 |
/**
|
127 |
* Init fields.
|
128 |
*
|
134 |
|
135 |
$this->form_fields = array(
|
136 |
'enabled' => array(
|
137 |
+
'title' => __( 'Enable/Disable', 'woocommerce' ),
|
138 |
+
'type' => 'checkbox',
|
139 |
+
'label' => __( 'Enable Advanced Free Shipping', 'woocommerce-advanced-free-shipping' ),
|
140 |
+
'default' => 'yes'
|
141 |
),
|
142 |
'hide_other_shipping' => array(
|
143 |
+
'title' => __( 'Hide other shipping', 'woocommerce-advanced-free-shipping' ),
|
144 |
+
'type' => 'checkbox',
|
145 |
+
'label' => __( 'Hide other shipping methods when free shipping is available', 'woocommerce-advanced-free-shipping' ),
|
146 |
+
'default' => 'no'
|
147 |
),
|
148 |
+
'conditions' => array(
|
149 |
+
'type' => 'conditions_table',
|
150 |
)
|
151 |
);
|
152 |
|
160 |
*
|
161 |
* @since 1.0.0
|
162 |
*
|
163 |
+
* @return string
|
164 |
*/
|
165 |
public function generate_conditions_table_html() {
|
166 |
|
183 |
*
|
184 |
* @since 1.0.0
|
185 |
*
|
186 |
+
* @param mixed $key Key.
|
187 |
+
* @return bool Validation.
|
188 |
*/
|
189 |
public function validate_additional_conditions_table_field( $key ) {
|
190 |
+
|
191 |
return false;
|
192 |
+
|
193 |
}
|
194 |
|
195 |
|
200 |
*
|
201 |
* @since 1.0.0
|
202 |
*
|
203 |
+
* @param mixed $package
|
204 |
*/
|
205 |
+
public function calculate_shipping( $package = array() ) {
|
206 |
|
207 |
if ( false == $this->matched_methods || 'no' == $this->enabled ) return;
|
208 |
|
209 |
+
$method_args = get_post_meta( $this->matched_methods, '_wafs_shipping_method', true );
|
210 |
+
$label = ! empty( $method_args['shipping_title'] ) ? $method_args['shipping_title'] : __( 'Free Shipping', 'woocommerce-advanced-free-shipping' );
|
211 |
|
212 |
$rate = array(
|
213 |
+
'id' => $this->id,
|
214 |
+
'label' => $label,
|
215 |
+
'cost' => '0',
|
216 |
);
|
217 |
|
218 |
// Register the rate
|
228 |
*
|
229 |
* @since 1.0.0
|
230 |
*
|
231 |
+
* @param array $available_methods
|
232 |
+
* @return array
|
233 |
*/
|
234 |
public function hide_all_shipping_when_free_is_available( $available_methods ) {
|
235 |
|
236 |
if ( 'no' == $this->hide_shipping ) return $available_methods;
|
237 |
|
238 |
+
if ( isset( $available_methods['advanced_free_shipping'] ) ) :
|
239 |
|
240 |
return array( 'advanced_free_shipping' => $available_methods['advanced_free_shipping'] );
|
241 |
|
242 |
+
elseif ( isset( $available_methods['free_shipping'] ) ) :
|
243 |
|
244 |
+
return array( 'free_shipping' => $available_methods['free_shipping'] );
|
245 |
|
246 |
+
else :
|
247 |
|
248 |
+
return $available_methods;
|
249 |
|
250 |
+
endif;
|
251 |
|
252 |
}
|
253 |
|
includes/class-wafs-post-type.php
CHANGED
@@ -28,13 +28,13 @@ class WAFS_post_type {
|
|
28 |
add_action( 'save_post', array( $this, 'save_meta' ) );
|
29 |
add_action( 'save_post', array( $this, 'save_condition_meta' ) );
|
30 |
|
31 |
-
|
32 |
add_filter( 'post_updated_messages', array( $this, 'custom_post_type_messages' ) );
|
33 |
|
34 |
// Redirect after delete
|
35 |
-
add_action('load-edit.php', array( $this, 'redirect_after_trash' ) );
|
36 |
|
37 |
-
|
38 |
|
39 |
|
40 |
/**
|
@@ -47,31 +47,31 @@ class WAFS_post_type {
|
|
47 |
public function register_post_type() {
|
48 |
|
49 |
$labels = array(
|
50 |
-
'name'
|
51 |
-
'singular_name'
|
52 |
-
'add_new'
|
53 |
-
'add_new_item'
|
54 |
-
'edit_item'
|
55 |
-
'new_item'
|
56 |
-
'view_item'
|
57 |
-
'search_items'
|
58 |
-
'not_found'
|
59 |
-
'not_found_in_trash'
|
60 |
);
|
61 |
|
62 |
register_post_type( 'wafs', array(
|
63 |
-
'label'
|
64 |
-
'show_ui'
|
65 |
-
'show_in_menu'
|
66 |
-
'public'
|
67 |
-
'publicly_queryable'
|
68 |
-
'capability_type'
|
69 |
-
'map_meta_cap'
|
70 |
-
'rewrite'
|
71 |
-
'_builtin'
|
72 |
-
'query_var'
|
73 |
-
'supports'
|
74 |
-
'labels'
|
75 |
) );
|
76 |
|
77 |
}
|
@@ -84,13 +84,13 @@ class WAFS_post_type {
|
|
84 |
*
|
85 |
* @since 1.0.0
|
86 |
*
|
87 |
-
* @param
|
88 |
-
* @return
|
89 |
*/
|
90 |
function custom_post_type_messages( $messages ) {
|
91 |
|
92 |
-
$post
|
93 |
-
$post_type
|
94 |
|
95 |
$messages['wafs'] = array(
|
96 |
0 => '',
|
@@ -241,9 +241,9 @@ class WAFS_post_type {
|
|
241 |
|
242 |
$screen = get_current_screen();
|
243 |
|
244 |
-
if( 'edit-wafs' == $screen->id ) :
|
245 |
|
246 |
-
if( isset( $_GET['trashed'] ) && intval( $_GET['trashed'] ) > 0 ) :
|
247 |
|
248 |
wp_redirect( admin_url( '/admin.php?page=wc-settings&tab=shipping§ion=wafs_free_shipping_method' ) );
|
249 |
exit();
|
28 |
add_action( 'save_post', array( $this, 'save_meta' ) );
|
29 |
add_action( 'save_post', array( $this, 'save_condition_meta' ) );
|
30 |
|
31 |
+
// Edit user messages
|
32 |
add_filter( 'post_updated_messages', array( $this, 'custom_post_type_messages' ) );
|
33 |
|
34 |
// Redirect after delete
|
35 |
+
add_action( 'load-edit.php', array( $this, 'redirect_after_trash' ) );
|
36 |
|
37 |
+
}
|
38 |
|
39 |
|
40 |
/**
|
47 |
public function 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(
|
63 |
+
'label' => 'wafs',
|
64 |
+
'show_ui' => true,
|
65 |
+
'show_in_menu' => false,
|
66 |
+
'public' => false,
|
67 |
+
'publicly_queryable' => false,
|
68 |
+
'capability_type' => 'post',
|
69 |
+
'map_meta_cap' => true,
|
70 |
+
'rewrite' => false,
|
71 |
+
'_builtin' => false,
|
72 |
+
'query_var' => true,
|
73 |
+
'supports' => array( 'title' ),
|
74 |
+
'labels' => $labels,
|
75 |
) );
|
76 |
|
77 |
}
|
84 |
*
|
85 |
* @since 1.0.0
|
86 |
*
|
87 |
+
* @param array $messages Existing list of messages.
|
88 |
+
* @return array Modified list of messages.
|
89 |
*/
|
90 |
function custom_post_type_messages( $messages ) {
|
91 |
|
92 |
+
$post = get_post();
|
93 |
+
$post_type = get_post_type( $post );
|
94 |
|
95 |
$messages['wafs'] = array(
|
96 |
0 => '',
|
241 |
|
242 |
$screen = get_current_screen();
|
243 |
|
244 |
+
if ( 'edit-wafs' == $screen->id ) :
|
245 |
|
246 |
+
if ( isset( $_GET['trashed'] ) && intval( $_GET['trashed'] ) > 0 ) :
|
247 |
|
248 |
wp_redirect( admin_url( '/admin.php?page=wc-settings&tab=shipping§ion=wafs_free_shipping_method' ) );
|
249 |
exit();
|
readme.txt
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
=== WooCommerce Advanced Free Shipping ===
|
2 |
Contributors: sormano
|
3 |
-
Donate link: http://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:
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -66,6 +65,10 @@ WooCommerce Advanced Free Shipping is an plugin which allows you to set up advan
|
|
66 |
|
67 |
== Changelog ==
|
68 |
|
|
|
|
|
|
|
|
|
69 |
= 1.0.8 - 22-12-2015 =
|
70 |
|
71 |
* [i18n] - Portuguese (pt_PT) translation
|
1 |
=== WooCommerce Advanced Free Shipping ===
|
2 |
Contributors: sormano
|
|
|
3 |
Tags: woocommerce, shipping, woocommerce shipping, woocommerce free shipping, woocommerce free, woocommerce advanced free shipping, wc free shipping, wc shipping, advanced shipping, pro shipping, table rate shipping, country shipping, free shipping
|
4 |
+
Requires at least: 4.0
|
5 |
+
Tested up to: 4.5.2
|
6 |
+
Stable tag: 1.0.9
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
65 |
|
66 |
== Changelog ==
|
67 |
|
68 |
+
= 1.0.9 - 16-06-2016 =
|
69 |
+
|
70 |
+
* [Fix] - Fix a notice that was introduced with a change in WooCommerce 2.6
|
71 |
+
|
72 |
= 1.0.8 - 22-12-2015 =
|
73 |
|
74 |
* [i18n] - Portuguese (pt_PT) translation
|
woocommerce-advanced-free-shipping.php
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
-
<?
|
2 |
/*
|
3 |
-
* Plugin Name:
|
4 |
* Plugin URI: https://wordpress.org/plugins/woocommerce-advanced-free-shipping/
|
5 |
-
* Donate link: http://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.
|
8 |
* Author: Jeroen Sormani
|
9 |
* Author URI: http://jeroensormani.com/
|
10 |
* Text Domain: woocommerce-advanced-free-shipping
|
@@ -49,7 +48,7 @@ class WooCommerce_Advanced_Free_Shipping {
|
|
49 |
* @since 1.0.4
|
50 |
* @var string $version Plugin version number.
|
51 |
*/
|
52 |
-
public $version = '1.0.
|
53 |
|
54 |
|
55 |
/**
|
@@ -78,8 +77,9 @@ class WooCommerce_Advanced_Free_Shipping {
|
|
78 |
*/
|
79 |
public function __construct() {
|
80 |
|
81 |
-
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
82 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
|
|
83 |
|
84 |
// Check if WooCommerce is active
|
85 |
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) :
|
@@ -101,7 +101,7 @@ class WooCommerce_Advanced_Free_Shipping {
|
|
101 |
*
|
102 |
* @since 1.1.0
|
103 |
*
|
104 |
-
* @return
|
105 |
*/
|
106 |
public static function instance() {
|
107 |
|
@@ -271,7 +271,9 @@ class WooCommerce_Advanced_Free_Shipping {
|
|
271 |
* @since 1.0.0
|
272 |
*/
|
273 |
public function wafs_admin_enqueue_scripts() {
|
|
|
274 |
_deprecated_function( __FUNCTION__, '1.0.8', 'WAFS()->admin->admin_enqueue_script()' );
|
|
|
275 |
}
|
276 |
|
277 |
|
@@ -287,14 +289,17 @@ class WooCommerce_Advanced_Free_Shipping {
|
|
287 |
*
|
288 |
* @since 1.1.0
|
289 |
*
|
290 |
-
* @return
|
291 |
*/
|
292 |
if ( ! function_exists( 'WAFS' ) ) :
|
293 |
|
294 |
-
|
|
|
295 |
return WooCommerce_Advanced_Free_Shipping::instance();
|
|
|
296 |
}
|
297 |
|
|
|
298 |
endif;
|
299 |
|
300 |
WAFS();
|
1 |
+
<?php
|
2 |
/*
|
3 |
+
* Plugin Name: WooCommerce Advanced Free Shipping
|
4 |
* Plugin URI: https://wordpress.org/plugins/woocommerce-advanced-free-shipping/
|
|
|
5 |
* Description: WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions.
|
6 |
+
* Version: 1.0.9
|
7 |
* Author: Jeroen Sormani
|
8 |
* Author URI: http://jeroensormani.com/
|
9 |
* Text Domain: woocommerce-advanced-free-shipping
|
48 |
* @since 1.0.4
|
49 |
* @var string $version Plugin version number.
|
50 |
*/
|
51 |
+
public $version = '1.0.9';
|
52 |
|
53 |
|
54 |
/**
|
77 |
*/
|
78 |
public function __construct() {
|
79 |
|
80 |
+
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
|
81 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
82 |
+
}
|
83 |
|
84 |
// Check if WooCommerce is active
|
85 |
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) :
|
101 |
*
|
102 |
* @since 1.1.0
|
103 |
*
|
104 |
+
* @return object Instance of the class.
|
105 |
*/
|
106 |
public static function instance() {
|
107 |
|
271 |
* @since 1.0.0
|
272 |
*/
|
273 |
public function wafs_admin_enqueue_scripts() {
|
274 |
+
|
275 |
_deprecated_function( __FUNCTION__, '1.0.8', 'WAFS()->admin->admin_enqueue_script()' );
|
276 |
+
|
277 |
}
|
278 |
|
279 |
|
289 |
*
|
290 |
* @since 1.1.0
|
291 |
*
|
292 |
+
* @return object WooCommerce_Advanced_Free_Shipping class object.
|
293 |
*/
|
294 |
if ( ! function_exists( 'WAFS' ) ) :
|
295 |
|
296 |
+
function WAFS() {
|
297 |
+
|
298 |
return WooCommerce_Advanced_Free_Shipping::instance();
|
299 |
+
|
300 |
}
|
301 |
|
302 |
+
|
303 |
endif;
|
304 |
|
305 |
WAFS();
|