Version Description
28-04-2017 =
[Fix] - Use 9 digit random IDs to prevent too big numbers for 32-bit systems
[Improvement] - Remove call to asset that no longer exists
Download this release
Release Info
Developer | sormano |
Plugin | WooCommerce Advanced Free Shipping |
Version | 1.1.1 |
Comparing to | |
See all releases |
Code changes from version 1.1.0 to 1.1.1
- includes/admin/class-wafs-admin.php +0 -7
- includes/core-functions.php +1 -1
- libraries/wp-conditions/assets/js/wp-conditions.js +2 -2
- libraries/wp-conditions/assets/js/wp-conditions.min.js +1 -1
- libraries/wp-conditions/conditions/wpc-city-condition.php +2 -15
- libraries/wp-conditions/conditions/wpc-condition.php +12 -0
- libraries/wp-conditions/conditions/wpc-contains-product-condition.php +4 -4
- libraries/wp-conditions/conditions/wpc-coupon-condition.php +10 -3
- libraries/wp-conditions/conditions/wpc-height-condition.php +5 -7
- libraries/wp-conditions/conditions/wpc-length-condition.php +5 -7
- libraries/wp-conditions/conditions/wpc-product-age-condition.php +79 -0
- libraries/wp-conditions/conditions/wpc-product-category-condition.php +55 -0
- libraries/wp-conditions/conditions/wpc-product-condition.php +60 -0
- libraries/wp-conditions/conditions/wpc-product-height-condition.php +40 -0
- libraries/wp-conditions/conditions/wpc-product-length-condition.php +40 -0
- libraries/wp-conditions/conditions/wpc-product-on-sale-condition.php +54 -0
- libraries/wp-conditions/conditions/wpc-product-price-condition.php +29 -0
- libraries/wp-conditions/conditions/wpc-product-sale-price-condition.php +29 -0
- libraries/wp-conditions/conditions/wpc-product-sales-condition.php +35 -0
- libraries/wp-conditions/conditions/wpc-product-shipping-class-condition.php +58 -0
- libraries/wp-conditions/conditions/wpc-product-stock-condition.php +45 -0
- libraries/wp-conditions/conditions/wpc-product-stock-status-condition.php +60 -0
- libraries/wp-conditions/conditions/wpc-product-tag-condition.php +70 -0
- libraries/wp-conditions/conditions/wpc-product-type-condition.php +53 -0
- libraries/wp-conditions/conditions/wpc-product-width-condition.php +40 -0
- libraries/wp-conditions/conditions/wpc-role-condition.php +10 -3
- libraries/wp-conditions/conditions/wpc-stock-condition.php +4 -6
- libraries/wp-conditions/conditions/wpc-stock-status-condition.php +37 -15
- libraries/wp-conditions/conditions/wpc-subtotal-condition.php +0 -1
- libraries/wp-conditions/conditions/wpc-time-condition.php +1 -1
- libraries/wp-conditions/conditions/wpc-volume-condition.php +37 -0
- libraries/wp-conditions/conditions/wpc-weight-condition.php +0 -1
- libraries/wp-conditions/conditions/wpc-width-condition.php +5 -7
- libraries/wp-conditions/conditions/wpc-zipcode-condition.php +14 -13
- libraries/wp-conditions/functions.php +38 -1
- libraries/wp-conditions/readme.txt +24 -0
- readme.txt +6 -1
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- woocommerce-advanced-free-shipping.php +2 -2
includes/admin/class-wafs-admin.php
CHANGED
@@ -54,13 +54,7 @@ class WAFS_Admin {
|
|
54 |
*/
|
55 |
public function admin_enqueue_scripts() {
|
56 |
|
57 |
-
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
58 |
-
|
59 |
wp_register_style( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/css/woocommerce-advanced-free-shipping.min.css', WAFS()->file ), array(), WAFS()->version );
|
60 |
-
wp_register_script( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/js/woocommerce-advanced-free-shipping' . $suffix . '.js', WAFS()->file ), array( 'jquery' ), WAFS()->version, true );
|
61 |
-
wp_localize_script( 'woocommerce-advanced-free-shipping', 'wafs', array(
|
62 |
-
'nonce' => wp_create_nonce( 'wpc-ajax-nonce' ),
|
63 |
-
) );
|
64 |
|
65 |
if (
|
66 |
( isset( $_REQUEST['post'] ) && 'wafs' == get_post_type( $_REQUEST['post'] ) ) ||
|
@@ -73,7 +67,6 @@ class WAFS_Admin {
|
|
73 |
) );
|
74 |
|
75 |
wp_enqueue_style( 'woocommerce-advanced-free-shipping' );
|
76 |
-
wp_enqueue_script( 'woocommerce-advanced-free-shipping' );
|
77 |
wp_enqueue_script( 'wp-conditions' );
|
78 |
|
79 |
wp_dequeue_script( 'autosave' );
|
54 |
*/
|
55 |
public function admin_enqueue_scripts() {
|
56 |
|
|
|
|
|
57 |
wp_register_style( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/css/woocommerce-advanced-free-shipping.min.css', WAFS()->file ), array(), WAFS()->version );
|
|
|
|
|
|
|
|
|
58 |
|
59 |
if (
|
60 |
( isset( $_REQUEST['post'] ) && 'wafs' == get_post_type( $_REQUEST['post'] ) ) ||
|
67 |
) );
|
68 |
|
69 |
wp_enqueue_style( 'woocommerce-advanced-free-shipping' );
|
|
|
70 |
wp_enqueue_script( 'wp-conditions' );
|
71 |
|
72 |
wp_dequeue_script( 'autosave' );
|
includes/core-functions.php
CHANGED
@@ -78,4 +78,4 @@ function wafs_add_bc_action_custom_fields( $type, $args ) {
|
|
78 |
}
|
79 |
|
80 |
}
|
81 |
-
add_action( 'wp-conditions\html_field_hook', 'wafs_add_bc_action_custom_fields' );
|
78 |
}
|
79 |
|
80 |
}
|
81 |
+
add_action( 'wp-conditions\html_field_hook', 'wafs_add_bc_action_custom_fields', 10, 2 );
|
libraries/wp-conditions/assets/js/wp-conditions.js
CHANGED
@@ -31,7 +31,7 @@ jQuery( function( $ ) {
|
|
31 |
|
32 |
// Assign new ID to repeater row + open collapsible + re-enable nested repeater
|
33 |
jQuery( document.body ).on( 'repeater-added-row', function( e, template, container, $self ) {
|
34 |
-
var new_id = Math.floor(Math.random()*
|
35 |
template.find( 'input[name], select[name]' ).attr( 'name', function( index, value ) {
|
36 |
return ( value.replace( '9999', new_id ) ) || value;
|
37 |
});
|
@@ -55,7 +55,7 @@ jQuery( function( $ ) {
|
|
55 |
condition_group_id = condition_group_wrap.find( '.wpc-condition-group' ).attr( 'data-group' ),
|
56 |
condition_group_list = $( this ).parents( '.wpc-conditions' ),
|
57 |
new_group = condition_group_wrap.clone(),
|
58 |
-
new_group_id = Math.floor(Math.random()*
|
59 |
|
60 |
// Fix dropdown selected not being cloned properly
|
61 |
$( condition_group_wrap ).find( 'select' ).each(function(i) {
|
31 |
|
32 |
// Assign new ID to repeater row + open collapsible + re-enable nested repeater
|
33 |
jQuery( document.body ).on( 'repeater-added-row', function( e, template, container, $self ) {
|
34 |
+
var new_id = Math.floor(Math.random()*899999999+100000000); // Random number sequence of 9 length
|
35 |
template.find( 'input[name], select[name]' ).attr( 'name', function( index, value ) {
|
36 |
return ( value.replace( '9999', new_id ) ) || value;
|
37 |
});
|
55 |
condition_group_id = condition_group_wrap.find( '.wpc-condition-group' ).attr( 'data-group' ),
|
56 |
condition_group_list = $( this ).parents( '.wpc-conditions' ),
|
57 |
new_group = condition_group_wrap.clone(),
|
58 |
+
new_group_id = Math.floor(Math.random()*899999999+100000000); // Random number sequence of 9 length
|
59 |
|
60 |
// Fix dropdown selected not being cloned properly
|
61 |
$( condition_group_wrap ).find( 'select' ).each(function(i) {
|
libraries/wp-conditions/assets/js/wp-conditions.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
jQuery(function($){function t(){$(".wpc-conditions").parents(".postbox").repeater({addTrigger:".wpc-condition-group-add",removeTrigger:".wpc-condition-group .delete",template:".wpc-condition-group-template .wpc-condition-group-wrap",elementWrap:".wpc-condition-group-wrap",elementsContainer:".wpc-conditions",removeElement:function(t){t.remove()}})}function o(){$(".wpc-condition-group").repeater({addTrigger:".wpc-condition-add",removeTrigger:".wpc-condition-delete",template:".wpc-condition-template .wpc-condition-wrap",elementWrap:".wpc-condition-wrap",elementsContainer:".wpc-conditions-list"})}t(),o(),jQuery(document.body).on("repeater-added-row",function(t,e,n,i){var a=Math.floor(
|
1 |
+
jQuery(function($){function t(){$(".wpc-conditions").parents(".postbox").repeater({addTrigger:".wpc-condition-group-add",removeTrigger:".wpc-condition-group .delete",template:".wpc-condition-group-template .wpc-condition-group-wrap",elementWrap:".wpc-condition-group-wrap",elementsContainer:".wpc-conditions",removeElement:function(t){t.remove()}})}function o(){$(".wpc-condition-group").repeater({addTrigger:".wpc-condition-add",removeTrigger:".wpc-condition-delete",template:".wpc-condition-template .wpc-condition-wrap",elementWrap:".wpc-condition-wrap",elementsContainer:".wpc-conditions-list"})}t(),o(),jQuery(document.body).on("repeater-added-row",function(t,e,n,i){var a=Math.floor(899999999*Math.random()+1e8);e.find("input[name], select[name]").attr("name",function(t,o){return o.replace("9999",a)||o}),e.find(".wpc-condition[data-id]").attr("data-id",function(t,o){return o.replace("9999",a)||o}),e.find("[data-group]").attr("data-group",function(t,o){return o.replace("9999",a)||o}),e.find(".repeater-active").removeClass("repeater-active"),o()}),$(document.body).on("click",".wpc-conditions .duplicate",function(){var t=$(this).parents(".wpc-condition-group-wrap"),e=t.find(".wpc-condition-group").attr("data-group"),n=$(this).parents(".wpc-conditions"),i=t.clone(),a=Math.floor(899999999*Math.random()+1e8);$(t).find("select").each(function(t){$(i).find("select").eq(t).val($(this).val())}),i.find(".wpc-condition-group").attr("data-group",a),i.find("input[name], select[name]").attr("name",function(t,o){return o.replace("conditions["+e+"]","conditions["+a+"]")}),i.find(".repeater-active").removeClass("repeater-active"),n.append(i),o(),$("html, body").on("scroll mousedown DOMMouseScroll mousewheel keydown touchmove",function(t){$("html, body").stop().off("scroll mousedown DOMMouseScroll mousewheel keydown touchmove")}),$("body, html").animate({scrollTop:$(i).offset().top-50},750,function(){$("html, body").off("scroll mousedown DOMMouseScroll mousewheel keydown touchmove")})}),$(document.body).on("change",".wpc-condition",function(){var t='<span style="width: calc( 42.5% - 75px ); border: 1px solid transparent; display: inline-block;"> </span>',o={action:wpc2.action_prefix+"update_condition_value",id:$(this).attr("data-id"),group:$(this).parents(".wpc-condition-group").attr("data-group"),condition:$(this).val(),nonce:wpc.nonce},e=$(this).parents(".wpc-condition-wrap").first(),n=".wpc-value-field-wrap";e.find(n).html(t).block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,o,function(t){e.find(n).replaceWith(t),$(document.body).trigger("wc-enhanced-select-init")});var i=e.find(".wpc-operator").val();e.find(".wpc-operator").empty().html(function(){var t=$(this),e=wpc.condition_operators[o.condition]||wpc.condition_operators["default"];$.each(e,function(o,e){t.append($("<option/>").attr("value",o).text(e)),t.val(i).val()||t.val(t.find("option:first").val())})}),e.find(".wpc-description").html(function(){return $('<span class="woocommerce-help-tip" />').attr("data-tip",wpc.condition_descriptions[o.condition]||"")}),$(".tips, .help_tip, .woocommerce-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}),$("#tiptip_holder").removeAttr("style"),$("#tiptip_arrow").removeAttr("style")}),$(".wpc-conditions-post-table.wpc-sortable-post-table tbody").sortable({items:"tr",handle:".sort",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(t,o){o.item.css("background-color","#f6f6f6")},stop:function(t,o){o.item.removeAttr("style")},update:function(t,o){$table=$(this).closest("table"),$table.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e={action:"wpc_save_post_order",form:$(this).closest("form").serialize(),nonce:wpc.nonce};$.post(ajaxurl,e,function(t){$(".wpc-conditions-post-table tbody tr:even").addClass("alternate"),$(".wpc-conditions-post-table tbody tr:odd").removeClass("alternate"),$table.unblock()})}})});
|
libraries/wp-conditions/conditions/wpc-city-condition.php
CHANGED
@@ -14,28 +14,15 @@ if ( ! class_exists( 'WPC_City_Condition' ) ) {
|
|
14 |
parent::__construct();
|
15 |
}
|
16 |
|
17 |
-
// @todo - Check if this can be cleaned up
|
18 |
public function match( $match, $operator, $value ) {
|
19 |
|
20 |
$value = $this->get_value( $value );
|
21 |
$customer_city = $this->get_compare_value();
|
22 |
|
23 |
if ( '==' == $operator ) :
|
24 |
-
|
25 |
-
if ( preg_match( '/\, ?/', $value ) ) :
|
26 |
-
$match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
|
27 |
-
else :
|
28 |
-
$match = ( $value == $customer_city );
|
29 |
-
endif;
|
30 |
-
|
31 |
elseif ( '!=' == $operator ) :
|
32 |
-
|
33 |
-
if ( preg_match( '/\, ?/', $value ) ) :
|
34 |
-
$match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
|
35 |
-
else :
|
36 |
-
$match = ( $value == $customer_city );
|
37 |
-
endif;
|
38 |
-
|
39 |
endif;
|
40 |
|
41 |
return $match;
|
14 |
parent::__construct();
|
15 |
}
|
16 |
|
|
|
17 |
public function match( $match, $operator, $value ) {
|
18 |
|
19 |
$value = $this->get_value( $value );
|
20 |
$customer_city = $this->get_compare_value();
|
21 |
|
22 |
if ( '==' == $operator ) :
|
23 |
+
$match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
elseif ( '!=' == $operator ) :
|
25 |
+
$match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
endif;
|
27 |
|
28 |
return $match;
|
libraries/wp-conditions/conditions/wpc-condition.php
CHANGED
@@ -98,6 +98,10 @@ if ( ! class_exists( 'WPC_Condition' ) ) {
|
|
98 |
|
99 |
public function match( $match, $operator, $value ) {
|
100 |
|
|
|
|
|
|
|
|
|
101 |
$value = $this->get_value( $value );
|
102 |
$compare_value = $this->get_compare_value();
|
103 |
|
@@ -114,6 +118,14 @@ if ( ! class_exists( 'WPC_Condition' ) ) {
|
|
114 |
return $match;
|
115 |
}
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
public function get_description() {
|
118 |
return $this->description;
|
119 |
}
|
98 |
|
99 |
public function match( $match, $operator, $value ) {
|
100 |
|
101 |
+
if ( ! $this->validate() ) {
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
|
105 |
$value = $this->get_value( $value );
|
106 |
$compare_value = $this->get_compare_value();
|
107 |
|
118 |
return $match;
|
119 |
}
|
120 |
|
121 |
+
/**
|
122 |
+
* Validates before matching function.
|
123 |
+
* Can be used for example to verify the global $product exists.
|
124 |
+
*/
|
125 |
+
public function validate() {
|
126 |
+
return true;
|
127 |
+
}
|
128 |
+
|
129 |
public function get_description() {
|
130 |
return $this->description;
|
131 |
}
|
libraries/wp-conditions/conditions/wpc-contains-product-condition.php
CHANGED
@@ -31,10 +31,10 @@ if ( ! class_exists( 'WPC_Contains_Product_Condition' ) ) {
|
|
31 |
public function get_compare_value() {
|
32 |
|
33 |
$product_ids = array();
|
34 |
-
foreach ( WC()->cart->
|
35 |
-
$product_ids[] = $
|
36 |
-
if ( isset( $
|
37 |
-
$product_ids[] = $
|
38 |
}
|
39 |
endforeach;
|
40 |
|
31 |
public function get_compare_value() {
|
32 |
|
33 |
$product_ids = array();
|
34 |
+
foreach ( WC()->cart->get_cart() as $item ) :
|
35 |
+
$product_ids[] = $item['product_id'];
|
36 |
+
if ( isset( $item['variation_id'] ) ) {
|
37 |
+
$product_ids[] = $item['variation_id'];
|
38 |
}
|
39 |
endforeach;
|
40 |
|
libraries/wp-conditions/conditions/wpc-coupon-condition.php
CHANGED
@@ -62,9 +62,16 @@ if ( ! class_exists( 'WPC_Coupon_Condition' ) ) {
|
|
62 |
|
63 |
$coupons = array( 'percent' => array(), 'fixed' => array() );
|
64 |
foreach ( WC()->cart->get_coupons() as $coupon ) {
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
}
|
69 |
|
70 |
return $coupons;
|
62 |
|
63 |
$coupons = array( 'percent' => array(), 'fixed' => array() );
|
64 |
foreach ( WC()->cart->get_coupons() as $coupon ) {
|
65 |
+
/** @var $coupon WC_Coupon */
|
66 |
+
if ( version_compare( WC()->version, '2.7', '>=' ) ) {
|
67 |
+
$type = str_replace( '_product', '', $coupon->get_discount_type() );
|
68 |
+
$type = str_replace( '_cart', '', $type );
|
69 |
+
$coupons[ $type ][] = $coupon->get_amount();
|
70 |
+
} else {
|
71 |
+
$type = str_replace( '_product', '', $coupon->discount_type );
|
72 |
+
$type = str_replace( '_cart', '', $type );
|
73 |
+
$coupons[ $type ][] = $coupon->coupon_amount;
|
74 |
+
}
|
75 |
}
|
76 |
|
77 |
return $coupons;
|
libraries/wp-conditions/conditions/wpc-height-condition.php
CHANGED
@@ -9,7 +9,7 @@ if ( ! class_exists( 'WPC_Height_Condition' ) ) {
|
|
9 |
$this->name = __( 'Height', 'wpc-conditions' );
|
10 |
$this->slug = __( 'height', 'wpc-conditions' );
|
11 |
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
-
$this->description = __( 'Compared to highest product in cart', 'wpc-conditions' );
|
13 |
|
14 |
parent::__construct();
|
15 |
}
|
@@ -17,13 +17,11 @@ if ( ! class_exists( 'WPC_Height_Condition' ) ) {
|
|
17 |
public function get_compare_value() {
|
18 |
|
19 |
$height = array();
|
20 |
-
foreach ( WC()->cart->get_cart() as $
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
$height[] = ( get_post_meta( $product['product_id'], '_height', true ) );
|
26 |
-
endif;
|
27 |
|
28 |
endforeach;
|
29 |
|
9 |
$this->name = __( 'Height', 'wpc-conditions' );
|
10 |
$this->slug = __( 'height', 'wpc-conditions' );
|
11 |
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compared to the highest product in cart', 'wpc-conditions' );
|
13 |
|
14 |
parent::__construct();
|
15 |
}
|
17 |
public function get_compare_value() {
|
18 |
|
19 |
$height = array();
|
20 |
+
foreach ( WC()->cart->get_cart() as $item ) :
|
21 |
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
$product = $item['data'];
|
24 |
+
$height[] = $product->get_height();
|
|
|
|
|
25 |
|
26 |
endforeach;
|
27 |
|
libraries/wp-conditions/conditions/wpc-length-condition.php
CHANGED
@@ -9,7 +9,7 @@ if ( ! class_exists( 'WPC_Length_Condition' ) ) {
|
|
9 |
$this->name = __( 'Length', 'wpc-conditions' );
|
10 |
$this->slug = __( 'length', 'wpc-conditions' );
|
11 |
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
-
$this->description = __( 'Compared to lengthiest product in cart', 'wpc-conditions' );
|
13 |
|
14 |
parent::__construct();
|
15 |
}
|
@@ -17,13 +17,11 @@ if ( ! class_exists( 'WPC_Length_Condition' ) ) {
|
|
17 |
public function get_compare_value() {
|
18 |
|
19 |
$length = array();
|
20 |
-
foreach ( WC()->cart->get_cart() as $
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
$length[] = ( get_post_meta( $product['product_id'], '_length', true ) );
|
26 |
-
endif;
|
27 |
|
28 |
endforeach;
|
29 |
|
9 |
$this->name = __( 'Length', 'wpc-conditions' );
|
10 |
$this->slug = __( 'length', 'wpc-conditions' );
|
11 |
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compared to the lengthiest product in cart', 'wpc-conditions' );
|
13 |
|
14 |
parent::__construct();
|
15 |
}
|
17 |
public function get_compare_value() {
|
18 |
|
19 |
$length = array();
|
20 |
+
foreach ( WC()->cart->get_cart() as $item ) :
|
21 |
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
$product = $item['data'];
|
24 |
+
$length[] = $product->get_length();
|
|
|
|
|
25 |
|
26 |
endforeach;
|
27 |
|
libraries/wp-conditions/conditions/wpc-product-age-condition.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Age_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Age_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product age', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_age', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product age', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function match( $match, $operator, $value ) {
|
18 |
+
|
19 |
+
if ( ! $this->validate() ) {
|
20 |
+
return false;
|
21 |
+
}
|
22 |
+
|
23 |
+
$raw_value = $value;
|
24 |
+
$value = $this->get_value( $value );
|
25 |
+
$compare_value = $this->get_compare_value();
|
26 |
+
|
27 |
+
if ( '==' == $operator ) :
|
28 |
+
$match = ( $compare_value == $value );
|
29 |
+
elseif ( '!=' == $operator ) :
|
30 |
+
$match = ( $compare_value != $value );
|
31 |
+
elseif ( '>=' == $operator ) :
|
32 |
+
if ( date( 'Y-m-d', strtotime( $raw_value ) ) > 1970 ) {
|
33 |
+
$match = ( $compare_value >= $value ); // Reversed operator intentional
|
34 |
+
} else {
|
35 |
+
$match = ( $compare_value <= $value );
|
36 |
+
}
|
37 |
+
elseif ( '<=' == $operator ) :
|
38 |
+
if ( date( 'Y-m-d', strtotime( $raw_value ) ) > 1970 ) {
|
39 |
+
$match = ( $compare_value <= $value );
|
40 |
+
} else {
|
41 |
+
$match = ( $compare_value >= $value ); // Reversed operator intentional
|
42 |
+
}
|
43 |
+
endif;
|
44 |
+
|
45 |
+
return $match;
|
46 |
+
|
47 |
+
}
|
48 |
+
|
49 |
+
public function get_value( $value ) {
|
50 |
+
|
51 |
+
if ( date( 'Y-m-d', strtotime( $value ) ) > 1970 ) {
|
52 |
+
$value = date( 'Y-m-d', strtotime( $value ) );
|
53 |
+
} else {
|
54 |
+
$value = date( 'Y-m-d', strtotime( "-$value days", time() ) );
|
55 |
+
}
|
56 |
+
|
57 |
+
return $value;
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
public function get_compare_value() {
|
62 |
+
/** @var $post WP_Post */
|
63 |
+
global $post;
|
64 |
+
return date( 'Y-m-d', strtotime( $post->post_date ) );
|
65 |
+
}
|
66 |
+
|
67 |
+
public function get_value_field_args() {
|
68 |
+
|
69 |
+
$field_args = array(
|
70 |
+
'placeholder' => __( 'Product age in days or date', 'woocommerce-advanced-product-labels' ),
|
71 |
+
);
|
72 |
+
|
73 |
+
return $field_args;
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
+
}
|
78 |
+
|
79 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-category-condition.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Category_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Category_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Category', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_category', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product categories', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function match( $match, $operator, $value ) {
|
22 |
+
|
23 |
+
if ( ! $this->validate() ) {
|
24 |
+
return false;
|
25 |
+
}
|
26 |
+
|
27 |
+
/** @var $product WC_Product */
|
28 |
+
global $product;
|
29 |
+
|
30 |
+
$value = $this->get_value( $value );
|
31 |
+
|
32 |
+
if ( '==' == $operator ) {
|
33 |
+
$match = $match = ( has_term( $value, 'product_cat', $product->get_id() ) );
|
34 |
+
} elseif ( '!=' == $operator ) {
|
35 |
+
$match = ! $match = ( has_term( $value, 'product_cat', $product->get_id() ) );
|
36 |
+
}
|
37 |
+
|
38 |
+
return $match;
|
39 |
+
|
40 |
+
}
|
41 |
+
|
42 |
+
public function get_available_operators() {
|
43 |
+
|
44 |
+
$operators = parent::get_available_operators();
|
45 |
+
|
46 |
+
unset( $operators['>='] );
|
47 |
+
unset( $operators['<='] );
|
48 |
+
|
49 |
+
return $operators;
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
}
|
54 |
+
|
55 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-condition.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the current product', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->get_id();
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_available_operators() {
|
28 |
+
|
29 |
+
$operators = parent::get_available_operators();
|
30 |
+
|
31 |
+
unset( $operators['>='] );
|
32 |
+
unset( $operators['<='] );
|
33 |
+
|
34 |
+
return $operators;
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
public function get_value_field_args() {
|
39 |
+
|
40 |
+
$field_args = array(
|
41 |
+
'type' => 'text',
|
42 |
+
'custom_attributes' => array(
|
43 |
+
'data-placeholder' => __( 'Search for a product', 'wp-conditions' ),
|
44 |
+
),
|
45 |
+
'class' => array( 'wpc-value', 'wc-product-search' ),
|
46 |
+
'options' => array(),
|
47 |
+
);
|
48 |
+
|
49 |
+
// Should be a select field in WC 2.7+
|
50 |
+
if ( version_compare( WC()->version, '2.7', '>=' ) ) {
|
51 |
+
$field_args['type'] = 'select';
|
52 |
+
}
|
53 |
+
|
54 |
+
return $field_args;
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-height-condition.php
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Height_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Height_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Height', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_height', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product height', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->get_height();
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_available_operators() {
|
28 |
+
|
29 |
+
$operators = parent::get_available_operators();
|
30 |
+
|
31 |
+
unset( $operators['>='] );
|
32 |
+
unset( $operators['<='] );
|
33 |
+
|
34 |
+
return $operators;
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-length-condition.php
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Length_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Length_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Length', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_length', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product length', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->get_length();
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_available_operators() {
|
28 |
+
|
29 |
+
$operators = parent::get_available_operators();
|
30 |
+
|
31 |
+
unset( $operators['>='] );
|
32 |
+
unset( $operators['<='] );
|
33 |
+
|
34 |
+
return $operators;
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-on-sale-condition.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_On_Sale_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_On_Sale_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product on sale', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_on_sale', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare if the product in on sale or not', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->is_on_sale();
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_available_operators() {
|
28 |
+
|
29 |
+
$operators = parent::get_available_operators();
|
30 |
+
|
31 |
+
unset( $operators['>='] );
|
32 |
+
unset( $operators['<='] );
|
33 |
+
|
34 |
+
return $operators;
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
public function get_value_field_args() {
|
39 |
+
|
40 |
+
$field_args = array(
|
41 |
+
'type' => 'select',
|
42 |
+
'options' => array(
|
43 |
+
'1' => __( 'Yes', 'woocommerce-advanced-product-labels' ),
|
44 |
+
'0' => __( 'No', 'woocommerce-advanced-product-labels' ),
|
45 |
+
),
|
46 |
+
);
|
47 |
+
|
48 |
+
return $field_args;
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
}
|
53 |
+
|
54 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-price-condition.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Price_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Price_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Price', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_price', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product price', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->get_price();
|
25 |
+
}
|
26 |
+
|
27 |
+
}
|
28 |
+
|
29 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-sale-price-condition.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Sale_Price_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Sale_Price_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Sale_Price', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_sale_price', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product sale price', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->get_sale_price();
|
25 |
+
}
|
26 |
+
|
27 |
+
}
|
28 |
+
|
29 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-sales-condition.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Sales_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Sales_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product sales', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_sales', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the total product sales', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
public function validate() {
|
19 |
+
return isset( $GLOBALS['product'] );
|
20 |
+
}
|
21 |
+
|
22 |
+
public function get_compare_value() {
|
23 |
+
/** @var $product WC_Product */
|
24 |
+
global $product;
|
25 |
+
|
26 |
+
if ( method_exists( $product, 'get_total_sales' ) ) { // WC 2.7
|
27 |
+
return $product->get_total_sales();
|
28 |
+
} else { // < WC 2.7
|
29 |
+
return get_post_meta( $product->get_id(), 'total_sales', true );
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-shipping-class-condition.php
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Shipping_Class_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Shipping_Class_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Shipping Class', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_shipping_class', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product shipping class', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->get_shipping_class();
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_available_operators() {
|
28 |
+
|
29 |
+
$operators = parent::get_available_operators();
|
30 |
+
|
31 |
+
unset( $operators['>='] );
|
32 |
+
unset( $operators['<='] );
|
33 |
+
|
34 |
+
return $operators;
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
public function get_value_field_args() {
|
39 |
+
|
40 |
+
$shipping_classes = get_terms( 'product_shipping_class', array( 'hide_empty' => false ) );
|
41 |
+
$shipping_classes = array_merge(
|
42 |
+
array( '-1' => __( 'No shipping class', 'woocommerce' ) ),
|
43 |
+
wp_list_pluck( $shipping_classes, 'name', 'slug' )
|
44 |
+
);
|
45 |
+
|
46 |
+
$field_args = array(
|
47 |
+
'type' => 'select',
|
48 |
+
'options' => $shipping_classes,
|
49 |
+
'class' => array( 'wpc-value', 'wc-enhanced-select' ),
|
50 |
+
);
|
51 |
+
|
52 |
+
return $field_args;
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-stock-condition.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Stock_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Stock_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Stock', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_stock', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product stock', 'wpc-conditions' );
|
13 |
+
// Alias: stock_quantity
|
14 |
+
|
15 |
+
parent::__construct();
|
16 |
+
}
|
17 |
+
|
18 |
+
public function validate() {
|
19 |
+
return isset( $GLOBALS['product'] );
|
20 |
+
}
|
21 |
+
|
22 |
+
// @todo - Improve
|
23 |
+
public function get_compare_value() {
|
24 |
+
/** @var $product WC_Product */
|
25 |
+
global $product;
|
26 |
+
// return $product->get_stock_quantity();
|
27 |
+
|
28 |
+
$stock_levels = array();
|
29 |
+
|
30 |
+
if ( $product->is_type( 'variable' ) ) {
|
31 |
+
foreach ( $product->get_children() as $variation ) {
|
32 |
+
$var = wc_get_product( $variation );
|
33 |
+
$stock_levels[] = $var->get_stock_quantity();
|
34 |
+
}
|
35 |
+
} else {
|
36 |
+
$stock_levels[] = $product->get_stock_quantity();
|
37 |
+
}
|
38 |
+
|
39 |
+
return max( $stock_levels );
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
}
|
44 |
+
|
45 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-stock-status-condition.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Stock_Status_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Stock_Status_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Stock Status', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_stock_status', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product stock status', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_value( $value ) {
|
22 |
+
$value = ( $value == 'instock' ) ? 1 : $value;
|
23 |
+
$value = ( $value == 'outofstock' ) ? 0 : $value;
|
24 |
+
return $value;
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_compare_value() {
|
28 |
+
/** @var $product WC_Product */
|
29 |
+
global $product;
|
30 |
+
return $product->is_in_stock();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function get_available_operators() {
|
34 |
+
|
35 |
+
$operators = parent::get_available_operators();
|
36 |
+
|
37 |
+
unset( $operators['>='] );
|
38 |
+
unset( $operators['<='] );
|
39 |
+
|
40 |
+
return $operators;
|
41 |
+
|
42 |
+
}
|
43 |
+
|
44 |
+
public function get_value_field_args() {
|
45 |
+
|
46 |
+
$field_args = array(
|
47 |
+
'type' => 'select',
|
48 |
+
'options' => array(
|
49 |
+
'1' => __( 'In stock', 'woocommerce' ),
|
50 |
+
'0' => __( 'Out of stock', 'woocommerce' ),
|
51 |
+
),
|
52 |
+
);
|
53 |
+
|
54 |
+
return $field_args;
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-tag-condition.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Tag_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Tag_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product tag', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_tag', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product tags', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function match( $match, $operator, $value ) {
|
22 |
+
|
23 |
+
if ( ! $this->validate() ) {
|
24 |
+
return false;
|
25 |
+
}
|
26 |
+
|
27 |
+
/** @var $product WC_Product */
|
28 |
+
global $product;
|
29 |
+
$value = $this->get_value( $value );
|
30 |
+
|
31 |
+
if ( $operator == '==' ) {
|
32 |
+
$match = ( has_term( $value, 'product_tag', $product->get_id() ) );
|
33 |
+
} elseif ( $operator == '!=' ) {
|
34 |
+
$match = ( ! has_term( $value, 'product_tag', $product->get_id() ) );
|
35 |
+
}
|
36 |
+
|
37 |
+
return $match;
|
38 |
+
|
39 |
+
}
|
40 |
+
|
41 |
+
public function get_available_operators() {
|
42 |
+
|
43 |
+
$operators = parent::get_available_operators();
|
44 |
+
|
45 |
+
unset( $operators['>='] );
|
46 |
+
unset( $operators['<='] );
|
47 |
+
|
48 |
+
return $operators;
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
public function get_value_field_args() {
|
54 |
+
|
55 |
+
$terms = get_terms( 'product_tag', array( 'hide_empty' => false ) );
|
56 |
+
|
57 |
+
$field_args = array(
|
58 |
+
'type' => 'select',
|
59 |
+
'options' => wp_list_pluck( $terms, 'name', 'slug' ),
|
60 |
+
'class' => array( 'wpc-value', 'wc-enhanced-select' ),
|
61 |
+
);
|
62 |
+
|
63 |
+
return $field_args;
|
64 |
+
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
}
|
69 |
+
|
70 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-type-condition.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Type_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Type_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product type', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the current product type', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->get_type();
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_available_operators() {
|
28 |
+
|
29 |
+
$operators = parent::get_available_operators();
|
30 |
+
|
31 |
+
unset( $operators['>='] );
|
32 |
+
unset( $operators['<='] );
|
33 |
+
|
34 |
+
return $operators;
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
public function get_value_field_args() {
|
39 |
+
|
40 |
+
$field_args['type'] = 'select';
|
41 |
+
|
42 |
+
$product_types = get_terms( 'product_type', array( 'hide_empty' => false ) );
|
43 |
+
foreach ( $product_types as $type ) {
|
44 |
+
$field_args['options'][ $type->slug ] = $type->name;
|
45 |
+
}
|
46 |
+
|
47 |
+
return $field_args;
|
48 |
+
|
49 |
+
}
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
}
|
libraries/wp-conditions/conditions/wpc-product-width-condition.php
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Product_Width_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Product_Width_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Product Width', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'product_width', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compare against the product width', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function validate() {
|
18 |
+
return isset( $GLOBALS['product'] );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
global $product;
|
24 |
+
return $product->get_width();
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_available_operators() {
|
28 |
+
|
29 |
+
$operators = parent::get_available_operators();
|
30 |
+
|
31 |
+
unset( $operators['>='] );
|
32 |
+
unset( $operators['<='] );
|
33 |
+
|
34 |
+
return $operators;
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
}
|
libraries/wp-conditions/conditions/wpc-role-condition.php
CHANGED
@@ -30,8 +30,13 @@ if ( ! class_exists( 'WPC_Role_Condition' ) ) {
|
|
30 |
}
|
31 |
|
32 |
public function get_compare_value() {
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
|
37 |
public function get_available_operators() {
|
@@ -48,11 +53,13 @@ if ( ! class_exists( 'WPC_Role_Condition' ) ) {
|
|
48 |
public function get_value_field_args() {
|
49 |
|
50 |
$user_roles = array_keys( get_editable_roles() );
|
|
|
|
|
51 |
|
52 |
$field_args = array(
|
53 |
'type' => 'select',
|
54 |
'class' => array( 'wpc-value' ),
|
55 |
-
'options' =>
|
56 |
);
|
57 |
|
58 |
return $field_args;
|
30 |
}
|
31 |
|
32 |
public function get_compare_value() {
|
33 |
+
if ( is_user_logged_in() ) {
|
34 |
+
global $current_user;
|
35 |
+
return $current_user->caps;
|
36 |
+
} else {
|
37 |
+
return array( 'not_logged_in' );
|
38 |
+
}
|
39 |
+
|
40 |
}
|
41 |
|
42 |
public function get_available_operators() {
|
53 |
public function get_value_field_args() {
|
54 |
|
55 |
$user_roles = array_keys( get_editable_roles() );
|
56 |
+
$user_roles = array_combine( $user_roles, $user_roles );
|
57 |
+
$user_roles['not_logged_in'] = __( 'Guest user', 'wp-conditions' );
|
58 |
|
59 |
$field_args = array(
|
60 |
'type' => 'select',
|
61 |
'class' => array( 'wpc-value' ),
|
62 |
+
'options' => $user_roles,
|
63 |
);
|
64 |
|
65 |
return $field_args;
|
libraries/wp-conditions/conditions/wpc-stock-condition.php
CHANGED
@@ -19,13 +19,11 @@ if ( ! class_exists( 'WPC_Stock_Condition' ) ) {
|
|
19 |
$stock = array();
|
20 |
|
21 |
// $package['contents']
|
22 |
-
foreach ( WC()->cart->get_cart() as $
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
$stock[] = ( get_post_meta( $product['product_id'], '_stock', true ) );
|
28 |
-
endif;
|
29 |
|
30 |
endforeach;
|
31 |
|
19 |
$stock = array();
|
20 |
|
21 |
// $package['contents']
|
22 |
+
foreach ( WC()->cart->get_cart() as $item ) :
|
23 |
|
24 |
+
/** @var $product WC_Product */
|
25 |
+
$product = $item['data'];
|
26 |
+
$stock[] = $product->get_stock_quantity();
|
|
|
|
|
27 |
|
28 |
endforeach;
|
29 |
|
libraries/wp-conditions/conditions/wpc-stock-status-condition.php
CHANGED
@@ -22,16 +22,19 @@ if ( ! class_exists( 'WPC_Stock_Status_Condition' ) ) {
|
|
22 |
|
23 |
$match = true;
|
24 |
// $package['contents']
|
25 |
-
foreach ( WC()->cart->get_cart() as $
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
if ( $stock_status != $value ) :
|
34 |
-
|
35 |
endif;
|
36 |
|
37 |
endforeach;
|
@@ -40,22 +43,27 @@ if ( ! class_exists( 'WPC_Stock_Status_Condition' ) ) {
|
|
40 |
|
41 |
$match = true;
|
42 |
// $package['contents']
|
43 |
-
foreach ( WC()->cart->get_cart() as $
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
50 |
|
51 |
if ( $stock_status == $value ) :
|
52 |
-
|
53 |
endif;
|
54 |
|
55 |
endforeach;
|
56 |
|
57 |
endif;
|
58 |
|
|
|
|
|
59 |
}
|
60 |
|
61 |
public function get_available_operators() {
|
@@ -69,6 +77,20 @@ if ( ! class_exists( 'WPC_Stock_Status_Condition' ) ) {
|
|
69 |
|
70 |
}
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
|
74 |
-
}
|
22 |
|
23 |
$match = true;
|
24 |
// $package['contents']
|
25 |
+
foreach ( WC()->cart->get_cart() as $item ) :
|
26 |
|
27 |
+
/** @var $product WC_Product */
|
28 |
+
$product = $item['data'];
|
29 |
+
|
30 |
+
if ( method_exists( $product, 'get_stock_status' ) ) { // WC 2.7 compatibility
|
31 |
+
$stock_status = $product->get_stock_status();
|
32 |
+
} else { // Pre 2.7
|
33 |
+
$stock_status = $product->stock_status;
|
34 |
+
}
|
35 |
|
36 |
if ( $stock_status != $value ) :
|
37 |
+
return false;
|
38 |
endif;
|
39 |
|
40 |
endforeach;
|
43 |
|
44 |
$match = true;
|
45 |
// $package['contents']
|
46 |
+
foreach ( WC()->cart->get_cart() as $item ) :
|
47 |
|
48 |
+
/** @var $product WC_Product */
|
49 |
+
$product = $item['data'];
|
50 |
+
|
51 |
+
if ( method_exists( $product, 'get_stock_status' ) ) { // WC 2.7 compatibility
|
52 |
+
$stock_status = $product->get_stock_status();
|
53 |
+
} else { // Pre 2.7
|
54 |
+
$stock_status = $product->stock_status;
|
55 |
+
}
|
56 |
|
57 |
if ( $stock_status == $value ) :
|
58 |
+
return false;
|
59 |
endif;
|
60 |
|
61 |
endforeach;
|
62 |
|
63 |
endif;
|
64 |
|
65 |
+
return $match;
|
66 |
+
|
67 |
}
|
68 |
|
69 |
public function get_available_operators() {
|
77 |
|
78 |
}
|
79 |
|
80 |
+
public function get_value_field_args() {
|
81 |
+
|
82 |
+
$field_args = array(
|
83 |
+
'type' => 'select',
|
84 |
+
'options' => array(
|
85 |
+
'1' => __( 'In stock', 'woocommerce' ),
|
86 |
+
'0' => __( 'Out of stock', 'woocommerce' ),
|
87 |
+
),
|
88 |
+
);
|
89 |
+
|
90 |
+
return $field_args;
|
91 |
+
|
92 |
+
}
|
93 |
+
|
94 |
}
|
95 |
|
96 |
+
}
|
libraries/wp-conditions/conditions/wpc-subtotal-condition.php
CHANGED
@@ -15,7 +15,6 @@ if ( ! class_exists( 'WPC_Subtotal_Condition' ) ) {
|
|
15 |
}
|
16 |
|
17 |
public function get_value( $value ) {
|
18 |
-
// Make sure its formatted correct
|
19 |
return str_replace( ',', '.', $value );
|
20 |
}
|
21 |
|
15 |
}
|
16 |
|
17 |
public function get_value( $value ) {
|
|
|
18 |
return str_replace( ',', '.', $value );
|
19 |
}
|
20 |
|
libraries/wp-conditions/conditions/wpc-time-condition.php
CHANGED
@@ -27,7 +27,7 @@ if ( ! class_exists( 'WPC_Time_Condition' ) ) {
|
|
27 |
$field_args = array(
|
28 |
'type' => 'text',
|
29 |
'class' => array( 'wpc-value' ),
|
30 |
-
'placeholder' => '
|
31 |
);
|
32 |
|
33 |
return $field_args;
|
27 |
$field_args = array(
|
28 |
'type' => 'text',
|
29 |
'class' => array( 'wpc-value' ),
|
30 |
+
'placeholder' => sprintf( __( 'Current time is: %s', 'woocommerce-advanced-messages' ), current_time( 'H:i' ) ),
|
31 |
);
|
32 |
|
33 |
return $field_args;
|
libraries/wp-conditions/conditions/wpc-volume-condition.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
if ( ! class_exists( 'WPC_Volume_Condition' ) ) {
|
5 |
+
|
6 |
+
class WPC_Volume_Condition extends WPC_Condition {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
$this->name = __( 'Volume', 'wpc-conditions' );
|
10 |
+
$this->slug = __( 'volume', 'wpc-conditions' );
|
11 |
+
$this->group = __( 'Cart', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Volume calculated on all the cart contents', 'wpc-conditions' );
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function get_value( $value ) {
|
18 |
+
return str_replace( ',', '.', $value );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_compare_value() {
|
22 |
+
$volume = 0;
|
23 |
+
|
24 |
+
// Get all product stocks
|
25 |
+
foreach ( WC()->cart->cart_contents as $item ) :
|
26 |
+
|
27 |
+
$product = wc_get_product( $item['data']->get_id() );
|
28 |
+
$volume += (float) ( $product->get_width() * $product->get_height() * $product->get_length() ) * $item['quantity'];
|
29 |
+
|
30 |
+
endforeach;
|
31 |
+
|
32 |
+
return $volume;
|
33 |
+
}
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
}
|
libraries/wp-conditions/conditions/wpc-weight-condition.php
CHANGED
@@ -15,7 +15,6 @@ if ( ! class_exists( 'WPC_Weight_Condition' ) ) {
|
|
15 |
}
|
16 |
|
17 |
public function get_value( $value ) {
|
18 |
-
// Make sure its formatted correct
|
19 |
return str_replace( ',', '.', $value );
|
20 |
}
|
21 |
|
15 |
}
|
16 |
|
17 |
public function get_value( $value ) {
|
|
|
18 |
return str_replace( ',', '.', $value );
|
19 |
}
|
20 |
|
libraries/wp-conditions/conditions/wpc-width-condition.php
CHANGED
@@ -9,7 +9,7 @@ if ( ! class_exists( 'WPC_Width_Condition' ) ) {
|
|
9 |
$this->name = __( 'Width', 'wpc-conditions' );
|
10 |
$this->slug = __( 'width', 'wpc-conditions' );
|
11 |
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
-
$this->description = __( 'Compared to widest product in cart', 'wpc-conditions' );
|
13 |
|
14 |
parent::__construct();
|
15 |
}
|
@@ -17,13 +17,11 @@ if ( ! class_exists( 'WPC_Width_Condition' ) ) {
|
|
17 |
public function get_compare_value() {
|
18 |
|
19 |
$width = array();
|
20 |
-
foreach ( WC()->cart->get_cart() as $
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
$width[] = ( get_post_meta( $product['product_id'], '_width', true ) );
|
26 |
-
endif;
|
27 |
|
28 |
endforeach;
|
29 |
|
9 |
$this->name = __( 'Width', 'wpc-conditions' );
|
10 |
$this->slug = __( 'width', 'wpc-conditions' );
|
11 |
$this->group = __( 'Product', 'wpc-conditions' );
|
12 |
+
$this->description = __( 'Compared to the widest product in cart', 'wpc-conditions' );
|
13 |
|
14 |
parent::__construct();
|
15 |
}
|
17 |
public function get_compare_value() {
|
18 |
|
19 |
$width = array();
|
20 |
+
foreach ( WC()->cart->get_cart() as $item ) :
|
21 |
|
22 |
+
/** @var $product WC_Product */
|
23 |
+
$product = $item['data'];
|
24 |
+
$width[] = $product->get_width();
|
|
|
|
|
25 |
|
26 |
endforeach;
|
27 |
|
libraries/wp-conditions/conditions/wpc-zipcode-condition.php
CHANGED
@@ -17,18 +17,7 @@ if ( ! class_exists( 'WPC_Zipcode_Condition' ) ) {
|
|
17 |
public function match( $match, $operator, $value ) {
|
18 |
|
19 |
$zipcode = $this->get_compare_value();
|
20 |
-
|
21 |
-
// Prepare the store-owner set value
|
22 |
-
$value_zipcodes = array();
|
23 |
-
if ( preg_match( '/\, ?/', $value ) ) :
|
24 |
-
|
25 |
-
foreach ( preg_split( '/\, ?/', $value ) as $v ) :
|
26 |
-
$value_zipcodes[] = preg_replace( '/[^0-9a-zA-Z\-]/', '', $v );
|
27 |
-
endforeach;
|
28 |
-
|
29 |
-
else :
|
30 |
-
$value_zipcodes[] = preg_replace( '/[^0-9a-zA-Z\-]/', '', $value );
|
31 |
-
endif;
|
32 |
|
33 |
// Match zipcode
|
34 |
if ( '==' == $operator ) :
|
@@ -43,7 +32,8 @@ if ( ! class_exists( 'WPC_Zipcode_Condition' ) ) {
|
|
43 |
|
44 |
$match = true;
|
45 |
foreach ( $value_zipcodes as $zip ) :
|
46 |
-
if (
|
|
|
47 |
break;
|
48 |
endif;
|
49 |
endforeach;
|
@@ -72,6 +62,17 @@ if ( ! class_exists( 'WPC_Zipcode_Condition' ) ) {
|
|
72 |
|
73 |
}
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
public function get_compare_value() {
|
76 |
return preg_replace( '/[^0-9a-zA-Z\-]/', '', WC()->customer->get_shipping_postcode() );
|
77 |
}
|
17 |
public function match( $match, $operator, $value ) {
|
18 |
|
19 |
$zipcode = $this->get_compare_value();
|
20 |
+
$value_zipcodes = $this->get_value( $value );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
// Match zipcode
|
23 |
if ( '==' == $operator ) :
|
32 |
|
33 |
$match = true;
|
34 |
foreach ( $value_zipcodes as $zip ) :
|
35 |
+
if ( preg_match( '/^' . preg_quote( $zip, '/' ) . '/i', $zipcode ) ) :
|
36 |
+
return $match = false;
|
37 |
break;
|
38 |
endif;
|
39 |
endforeach;
|
62 |
|
63 |
}
|
64 |
|
65 |
+
public function get_value( $value ) {
|
66 |
+
|
67 |
+
$value_zipcodes = array();
|
68 |
+
foreach ( preg_split( '/\, ?/', $value ) as $v ) :
|
69 |
+
$value_zipcodes[] = preg_replace( '/[^0-9a-zA-Z\-]/', '', $v );
|
70 |
+
endforeach;
|
71 |
+
|
72 |
+
return $value_zipcodes;
|
73 |
+
|
74 |
+
}
|
75 |
+
|
76 |
public function get_compare_value() {
|
77 |
return preg_replace( '/[^0-9a-zA-Z\-]/', '', WC()->customer->get_shipping_postcode() );
|
78 |
}
|
libraries/wp-conditions/functions.php
CHANGED
@@ -32,13 +32,31 @@ require_once 'conditions/wpc-state-condition.php';
|
|
32 |
require_once 'conditions/wpc-country-condition.php';
|
33 |
require_once 'conditions/wpc-role-condition.php';
|
34 |
|
|
|
35 |
require_once 'conditions/wpc-length-condition.php';
|
36 |
require_once 'conditions/wpc-width-condition.php';
|
37 |
require_once 'conditions/wpc-height-condition.php';
|
38 |
require_once 'conditions/wpc-stock-status-condition.php';
|
39 |
require_once 'conditions/wpc-stock-condition.php';
|
40 |
require_once 'conditions/wpc-category-condition.php';
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
if ( ! function_exists( 'wpc_get_registered_conditions' ) ) {
|
44 |
|
@@ -78,6 +96,23 @@ if ( ! function_exists( 'wpc_get_registered_conditions' ) ) {
|
|
78 |
new WPC_Stock_Status_Condition(),
|
79 |
new WPC_Stock_Condition(),
|
80 |
new WPC_Category_Condition(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
);
|
82 |
|
83 |
return apply_filters( 'wp-conditions\registered_conditions', $conditions );
|
@@ -102,6 +137,8 @@ if ( ! function_exists( 'wpc_get_condition' ) ) {
|
|
102 |
function wpc_get_condition( $condition ) {
|
103 |
|
104 |
$class_name = 'WPC_' . implode( '_', array_map( 'ucfirst', explode( '_', $condition ) ) ) . '_Condition';
|
|
|
|
|
105 |
if ( class_exists( $class_name ) ) {
|
106 |
return new $class_name();
|
107 |
} else {
|
32 |
require_once 'conditions/wpc-country-condition.php';
|
33 |
require_once 'conditions/wpc-role-condition.php';
|
34 |
|
35 |
+
// Product (cart based)
|
36 |
require_once 'conditions/wpc-length-condition.php';
|
37 |
require_once 'conditions/wpc-width-condition.php';
|
38 |
require_once 'conditions/wpc-height-condition.php';
|
39 |
require_once 'conditions/wpc-stock-status-condition.php';
|
40 |
require_once 'conditions/wpc-stock-condition.php';
|
41 |
require_once 'conditions/wpc-category-condition.php';
|
42 |
+
require_once 'conditions/wpc-volume-condition.php';
|
43 |
+
|
44 |
+
// Product (single based)
|
45 |
+
require_once 'conditions/wpc-product-condition.php';
|
46 |
+
require_once 'conditions/wpc-product-age-condition.php';
|
47 |
+
require_once 'conditions/wpc-product-type-condition.php';
|
48 |
+
require_once 'conditions/wpc-product-category-condition.php';
|
49 |
+
require_once 'conditions/wpc-product-shipping-class-condition.php';
|
50 |
+
require_once 'conditions/wpc-product-tag-condition.php';
|
51 |
+
require_once 'conditions/wpc-product-height-condition.php';
|
52 |
+
require_once 'conditions/wpc-product-length-condition.php';
|
53 |
+
require_once 'conditions/wpc-product-price-condition.php';
|
54 |
+
require_once 'conditions/wpc-product-sale-price-condition.php';
|
55 |
+
require_once 'conditions/wpc-product-stock-condition.php';
|
56 |
+
require_once 'conditions/wpc-product-stock-status-condition.php';
|
57 |
+
require_once 'conditions/wpc-product-width-condition.php';
|
58 |
+
require_once 'conditions/wpc-product-sales-condition.php';
|
59 |
+
require_once 'conditions/wpc-product-on-sale-condition.php';
|
60 |
|
61 |
if ( ! function_exists( 'wpc_get_registered_conditions' ) ) {
|
62 |
|
96 |
new WPC_Stock_Status_Condition(),
|
97 |
new WPC_Stock_Condition(),
|
98 |
new WPC_Category_Condition(),
|
99 |
+
new WPC_Volume_Condition(),
|
100 |
+
|
101 |
+
new WPC_Product_Condition(),
|
102 |
+
new WPC_Product_Age_Condition(),
|
103 |
+
new WPC_Product_Type_Condition(),
|
104 |
+
new WPC_Product_Length_Condition(),
|
105 |
+
new WPC_Product_Width_Condition(),
|
106 |
+
new WPC_Product_Height_Condition(),
|
107 |
+
new WPC_Product_Stock_Status_Condition(),
|
108 |
+
new WPC_Product_Stock_Condition(),
|
109 |
+
new WPC_Product_Category_Condition(),
|
110 |
+
new WPC_Product_Shipping_Class_Condition(),
|
111 |
+
new WPC_Product_Tag_Condition(),
|
112 |
+
new WPC_Product_Price_Condition(),
|
113 |
+
new WPC_Product_Sale_Price_Condition(),
|
114 |
+
new WPC_Product_Sales_Condition(),
|
115 |
+
new WPC_Product_On_Sale_Condition(),
|
116 |
);
|
117 |
|
118 |
return apply_filters( 'wp-conditions\registered_conditions', $conditions );
|
137 |
function wpc_get_condition( $condition ) {
|
138 |
|
139 |
$class_name = 'WPC_' . implode( '_', array_map( 'ucfirst', explode( '_', $condition ) ) ) . '_Condition';
|
140 |
+
$class_name = apply_filters( 'wpc_get_condition_class_name', $class_name, $condition );
|
141 |
+
|
142 |
if ( class_exists( $class_name ) ) {
|
143 |
return new $class_name();
|
144 |
} else {
|
libraries/wp-conditions/readme.txt
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
WP Conditions is a framework developed by Jeroen Sormani <info@jeroensormani.com>
|
2 |
+
It is intended to be used on plugins like build by Jeroen such as Advanced Shipping, Advanced Fees etc.
|
3 |
+
|
4 |
+
Copyright © 2017 Jeroen Sormani
|
5 |
+
|
6 |
+
|
7 |
+
# Current version: 1.0.2
|
8 |
+
|
9 |
+
# Changelog
|
10 |
+
|
11 |
+
= 1.0.2 - 28/04/2017 =
|
12 |
+
|
13 |
+
- [Add] - Volume condition
|
14 |
+
- [Add] - Support for 'Guest' users in the 'User role' condition
|
15 |
+
- [Fix] - Use 9 length IDs for new fields - prevents too big numbers for 32-bits systems.
|
16 |
+
|
17 |
+
|
18 |
+
= 1.0.1 =
|
19 |
+
|
20 |
+
- [Add] - WC 3.0 compatibility
|
21 |
+
|
22 |
+
= 1.0.0 =
|
23 |
+
|
24 |
+
First release
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ 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.7.3
|
6 |
-
Stable tag: 1.1.
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
@@ -99,6 +99,11 @@ In the future this will likely be changed, for now I recommend taking a look at
|
|
99 |
|
100 |
== Changelog ==
|
101 |
|
|
|
|
|
|
|
|
|
|
|
102 |
= 1.1.0 - 06-03-2017 = IMPORTANT NOTE - As of this version, the plugin requires PHP 5.3 or higher to function
|
103 |
|
104 |
* [Fix] - Allow variations to be set (and make them working) with the 'contains product' condition
|
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.7.3
|
6 |
+
Stable tag: 1.1.1
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
99 |
|
100 |
== Changelog ==
|
101 |
|
102 |
+
= 1.1.1 - 28-04-2017 =
|
103 |
+
|
104 |
+
* [Fix] - Use 9 digit random IDs to prevent too big numbers for 32-bit systems
|
105 |
+
* [Improvement] - Remove call to asset that no longer exists
|
106 |
+
|
107 |
= 1.1.0 - 06-03-2017 = IMPORTANT NOTE - As of this version, the plugin requires PHP 5.3 or higher to function
|
108 |
|
109 |
* [Fix] - Allow variations to be set (and make them working) with the 'contains product' condition
|
screenshot-1.png
DELETED
Binary file
|
screenshot-2.png
DELETED
Binary file
|
screenshot-3.png
DELETED
Binary file
|
woocommerce-advanced-free-shipping.php
CHANGED
@@ -3,7 +3,7 @@
|
|
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.1.
|
7 |
* Author: Jeroen Sormani
|
8 |
* Author URI: http://jeroensormani.com/
|
9 |
* Text Domain: woocommerce-advanced-free-shipping
|
@@ -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.1.
|
52 |
|
53 |
|
54 |
/**
|
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.1.1
|
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.1.1';
|
52 |
|
53 |
|
54 |
/**
|